13 Replies Latest reply on Apr 24, 2009 1:04 PM by billworld

    self problem within field definition calcs

    billworld

      Summary

      self problem within field definition calcs

      Description of the issue

      The following code does not work within field defeinition calcs but DOES work within auto-enter calcs. RightWords ( GetFieldName (Self) ; 1 )Using GetAsText() doesn't help.The docs for Self say the following:-------You can also use the Self function in field definition calculations (including auto-enter and validation calculations) to return the value of the corresponding field.-------Something should be added indicating that Self-derived values in field definition calcs cannot be further evaluated once their value is obtained. Or, is this a functionality error (e.g. bug?) which needs to be corrected? For my application, I desire the ability to have the following code work within field definition calcs to make my code more dynamic and portable: RightWords ( GetFieldName (Self) ; 1 ) 

        • 1. Re: self problem within field definition calcs
          TSGal

          billworld:

           

          Thank you for your post.

           

          This will not work if the calculation is unstored.  Therefore, remove the check mark for "Do not store calculation results" under Storage Options...

           

          TSGal

          FileMaker, Inc. 

          • 2. Re: self problem within field definition calcs
            billworld
              

            For my purposes, the calculation needs to be unstored as there are other routines going on which are dynamic.

             

            It doesn't make sense why the following code doesn't work in field definition calculations:


            RightWords ( GetFieldName ( Self ) ; 1 ) 

            But, the following code DOES work in field definition calcs:

            GetFieldName ( Self )

            Even with an Evaluate ( ) inserted and/or a window refresh (manually), RightWords (and other functions) don't act on GetFieldName ( Self ) within field definition calcs but they do within Auto-Enter calcs. 

            If GetFieldName ( Self ) gets the value okay, why can't RightWords() (and other functions) operate on said value?

            That doesn't make sense to me. 

             

            And, the docs don't specify that this kind of routine does not work in unstored calcs. That's why the functionality appears to not work as intended (e.g. it's a bug).

            • 3. Re: self problem within field definition calcs
              philmodjunk
                

              I don't think "self" is the issue.

               

              If your field were named "TextField"

               

              Rightwords(getfieldname(textfield),1) will give you identical results, I expect.

              • 4. Re: self problem within field definition calcs
                billworld
                  

                You're right. I only mentioned Self as someone else pointed to it in a different thread elsewhere on this issue.

                 

                Anyway, the issue remains:

                 

                How do you grab a portion of a field name and use it within a field def. calc?

                 

                GetFieldName grabs the name properly, but, then you can't do anything with it. That seems odd to me. 

                • 5. Re: self problem within field definition calcs
                  philmodjunk
                    

                  billworld wrote:

                   

                  GetFieldName grabs the name properly, but, then you can't do anything with it. That seems odd to me. 


                  Only when your calculated field refers to itself.

                   

                  If I define field "x" as

                   

                  x + 1

                   

                  That's not going to work either.


                  • 6. Re: self problem within field definition calcs
                    billworld
                      

                    PhilModJunk wrote:

                    billworld wrote:

                     

                    GetFieldName grabs the name properly, but, then you can't do anything with it. That seems odd to me. 


                    Only when your calculated field refers to itself.

                     

                    If I define field "x" as

                     

                    x + 1

                     

                    That's not going to work either.


                     
                    I don't follow the X + 1 example. If field X is named "field_1" and I want to do a mathematical operation based on the "1" portion of the field name (after RightWords and casting as number type via GetAsNumber()) why shouldn't that work?
                    The phrase "Only when your calculated field refers to itself." is the gist of what the Self function is all about, no? So, I'm still not clear why FMP gives the fieldname info (via GetFieldName) but then prevents one from really doing anything with it.
                    I'm simply trying to have routines which allow for a single calculation to be copied/pasted to multiple fields and yield different results in said calc based on a portion of the field name (such as a trailing suffix, e.g. "fieldname_subject"). I can return "fieldname_subject" in an unstored field definition calc via GetFieldName, but, then I can't wrap any other function (such as RightWords) around it and obtain the desired value.
                    Seems logical to me. What's confusing is that this works in Auto-Enter calcs and in stored calcs but not in unstored calcs. 
                     


                    • 7. Re: self problem within field definition calcs
                      billworld
                        

                      Adding to this issue is the following related issue a colleague brought to my attention elsewhere which I have just confirmed also fails. Definitely something wrong with GetFieldName and/or Self.

                       

                      ----- 

                      Bill, 
                      I've experienced this. Put each of the following two calcs in unstored fields and you get interesting results. 

                      GetFieldName ( Self ) & "X" = Table::Field 

                      "X " & GetFieldName ( Self ) =X Table::Field 

                      It seems that after the GetFieldName(Self), nothing evaluates. 

                      ----- 




                      • 8. Re: self problem within field definition calcs
                        D_J
                          

                        Bill,

                        Looking into it more, try this:  1 & GetFieldName(Self) & 1

                         

                        I think GetFieldName(Self) is a very useful tool, specifically for use with the script step Set Field by Name.

                         

                        And while FMI apparently intended for it to be used in field calculations, (from the help file as an example: "GetFieldName(Self) returns Personnel::Name from the Name field in the Personnel table" ) I have yet found a need to use it in fields yet, so I don't understand how its requirement to be stored is limiting. 

                         

                         

                         PS: I was the one who posted the "X" & GetFieldName(Self) example on the Tech Talk forum. 

                        • 9. Re: self problem within field definition calcs
                          philmodjunk
                            

                          Scratch that example on X + 1. It doesn't make any sense to me either :smileyvery-happy:.

                           

                          • 10. Re: self problem within field definition calcs
                            TSGal

                            billworld (and all):

                             

                            Sorry for the late reply.

                             

                            My initial post was based upon the information available I had at the time .  Without a real-life example, I'm still having difficulty understanding why this result needs to be unstored.

                             

                            Still, you're right.  It doesn't work as it seems to be intended.

                             

                            A question mark usually signifies endless recursion, and since the field is referencing itself, that could be a cause, but then again, why wouldn't this also show for GetFieldName (Self)?

                             

                            I have forwarded this information to our Development and Software Quality Assurance (Testing) departments for review.  When I receive more information, I'll let you know.

                             

                            In the mean time, you can either display it as stored, or divide this into two fields.  That is, the first field to display GetFieldName (Self), and then an extra field to use RightWords () on the first field.  It is extra overhead, but it does work with both calculations unstored.

                             

                            TSGal

                            FileMaker, Inc. 

                             

                             

                            • 11. Re: self problem within field definition calcs
                              billworld
                                

                              billworld wrote:
                              The following code does not work within field defeinition calcs but DOES work within auto-enter calcs.
                               
                              RightWords ( GetFieldName (Self) ; 1 )

                              Using GetAsText() doesn't help.

                              The docs for Self say the following:

                              -------
                              You can also use the Self function in field definition calculations (including auto-enter and validation calculations) to return the value of the corresponding field.
                              -------

                              Something should be added indicating that Self-derived values in field definition calcs cannot be further evaluated once their value is obtained. Or, is this a functionality error (e.g. bug?) which needs to be corrected?
                               
                              For my application, I desire the ability to have the following code work within field definition calcs to make my code more dynamic and portable:
                               
                              RightWords ( GetFieldName (Self) ; 1 ) 

                               
                              The simple reason why this needs to work in unstored calcs is that in addition to the routine which plays off of the field name there are scenarios where one would need to combine this info with other routines which are dynamically calculated. That's exactly the scenario I'm faced with currently.
                              Regardless, the docs don't say that it only works in unstored calcs. So, the functionality doesn't operate either as documented or as desired or as expected. If I can grab the fieldname via GetFieldName, I should be able to have other functions operate on it as expected in unstored calcs. Makes sense, right?
                              And, I should be able to do this without explaining "why" I want to do this. The workaround of creating two calc fields doesn't help for my purposes. I'm just resorting to hard-coding the value that should otherwise be derived from the unstored calc operating on Self via GetFieldName.
                              Why? I have dozens of calcs where this is required. So, doubling the number of calcs to overcome the bug isn't as efficient as my current workaround which is simply to hard-code the needed value in each calc. 
                               
                               

                               


                              • 12. Re: self problem within field definition calcs
                                TSGal

                                billworld:

                                 

                                Testing has verified the findings and has sent it on to Development for more comments.  I'll keep you posted.

                                 

                                When a problem is submitted, we try to provide real-life examples so others can visualize what the customers are trying to accomplish.  They can say to themselves, "I can see why that is needed", and therefore put more attention to it and/or give it a higher priority.  I apologize if you interpreted this as an intrusion.

                                 

                                I agree this is not performing as stated in the manual.  I have reported it to the appropriate departments, and I will post again when I have more information.

                                 

                                Now that you told me that you have "dozens of calcs where this is required", I agree the workaround is unacceptable.  Unfortunately, that's all I have right now.

                                 

                                Does anyone else have ideas for billworld? 

                                 

                                TSGal

                                FileMaker, Inc.

                                • 13. Re: self problem within field definition calcs
                                  billworld
                                    

                                  TSGal wrote:

                                  billworld:

                                   

                                  Testing has verified the findings and has sent it on to Development for more comments.  I'll keep you posted.

                                   

                                  When a problem is submitted, we try to provide real-life examples so others can visualize what the customers are trying to accomplish.  They can say to themselves, "I can see why that is needed", and therefore put more attention to it and/or give it a higher priority.  I apologize if you interpreted this as an intrusion.

                                   

                                  I agree this is not performing as stated in the manual.  I have reported it to the appropriate departments, and I will post again when I have more information.

                                   

                                  Now that you told me that you have "dozens of calcs where this is required", I agree the workaround is unacceptable.  Unfortunately, that's all I have right now.

                                   

                                  Does anyone else have ideas for billworld? 

                                   

                                  TSGal

                                  FileMaker, Inc.


                                  Thanks. My current workaround is fine. Don't need to spin any more cycles trying to come up with an alternative approach. When reporting bugs, I think it best just to focus on the line of code which doesn't work as expected rather than try to explain an entire example or solution. All too often that leads to confusion as to the initial problem. 
                                  Anyway, my first post had the line of code that wasn't working. 
                                  Thanks again for the follow up.