1 2 Previous Next 27 Replies Latest reply on Jun 15, 2015 7:54 AM by disabled_JustinClose

    If Function Problem



      If Function Problem


      I have an If function that checks 2 "Yes/No" text fields;  If A="Yes" and B="No", SetField.

      My test fields are set accordingly and the If functions fails.  I used Data Viewer and found that the second part of the IF, B="No" is the problem.  I've checked and verified field B (text field) on the layout and in the table.  Up to this point Field B is a manual input field, it is set to "Yes" several script steps later.

      I'm not able to find what's causing the problem.

      Any suggestions?


        • 1. Re: If Function Problem


          Could you post the exact formula in your IF statement, please?

             It sounds like you have already started down the road of looking at things in the Data Viewer, but here is how I would approach the problem:

          Set a 'Watch', defined (A="Yes")  [should result in a 1/0]

          Set a 'Watch', defined (B="No")  [should result in a 1/0]

          Set a 'Watch', defined to Table::B, in order to show the value(s) that are in B. 

          Then I would manually walk through the records that I was interested in and see how these values changed. 

          You mentioned that B was a manual input field; it is possible that there are extra things getting set into the field.  So it may look like "No" to you, the human, but perhaps there is a 2nd line of data, or stray characters (e.g. a space).

          --  Justin

          • 2. Re: If Function Problem

            Set a "Watch" is how I isolated and found the problem, thanks for the suggestion.

            T01b1_orders_Confirmed||_pkUniqueID::Recvin = "yes" and T01b1_orders_Confirmed||_pkUniqueID::In_Inventory= "no"

            • 3. Re: If Function Problem

              Yes, but did you watch the actual data or just the result?  There is some reason that your logic check isn't evaluating that you think it should be, and the calculation that you have outlined seems simple enough to not be an actual logical problem.  Thus it must be something in the data itself.  You mentioned manual entry, which is highly susceptible to erroneous values.  Or maybe I'm misunderstanding what you mean by 'manual entry'.

              You could define a watch as 'code(In_Inventory)' to see if there are weird characters involved.


              • 4. Re: If Function Problem

                I watched the results, I didn't know that the actual data could be viewed. Regarding "manual entry" I tab to or put the incursion cursor in the In_Inventory field and type "no" and yesterday I even tried setting the field with a script step but still got the same results.

                • 5. Re: If Function Problem

                  Up to this point Field B is a manual input field

                  Unless you have the field set up with a value list of yes or no and do not allow the user to enter different values, the user might enter the correct value but also enter a leading or trailing space. The value inf the field thus might look like "yes" or "no", but actually be "yes " or "no " and that will cause your calculation to fail. You can use patterncount to look for "yes" or no within a larger string or use trim to remove leading and trailing spaces, but using a format and value list that limits the user to exactly "yes" or "no" would be better.

                  • 6. Re: If Function Problem


                    Did you try using the Code() function to see what the actual characters in the field were, to see if there were any extras?  If you have the field In_Inventory holds the  word "yes", then the output of Code(TableA::In_Inventory) should be: 1150010100121.  If the field holds "no", then it is:  11100110

                    What Phil suggested about using a value list is the best way forward, then your users can't enter weird data.

                    • 7. Re: If Function Problem

                      I try using both of the example given;

                      For the Code() function Code ( T01b1_orders_Confirmed||_pkUniqueID::In_Inventory= "no" ), the value returned was 48 and

                      For the PatternCount function PatternCount ( T01b1_orders_Confirmed||_pkUniqueID::In_Inventory ; "no" ), the function falied (0)


                      • 8. Re: If Function Problem

                        Hey Ricard,

                        The code function should just be used on the value in the field itself, not on the full logic expression.  So the watch definition would be this:

                        code ( T01b1_orders_Confirmed||_pkUniqueID::In_Inventory )

                        That should result in "11100110" if the field contains "no".  (Uppercase letters are different values, so "No" would be something else.)  The key here is that there are only two characters represented by the result of the Code() function.  The results of Code() can be a bit confusing to interpret, but in this case the first three digits, "111" represent the letter "o", and the next 5 digits "00110" represent the "n".  If you had a third character, you would see another set of 5 digits appear in the output.

                        The result "48" that you got was the code() value of the number zero, "0", because that is the result of the logic statement that you put inside the Code function.  So it evaluated the logic first, and then passed that result to Code.

                        The fact that the PatternCount() is failing seems to indicate that field doesn't contain the word you think it does.

                        -- Justin

                        • 9. Re: If Function Problem

                          Code ( T01b1_orders_Confirmed||_pkUniqueID::In_Inventory) results 1150010100089

                          • 10. Re: If Function Problem

                            So that's a "Yes" value.  What about for a record that looks like a "no" or that you think should be a "no"?

                            • 11. Re: If Function Problem

                              What I just posted is for the record that should have a "no" in the In_Inventory field.

                              I walked through the input process again, I typed "no" the in In_Inventory field and ran the if function script and it still fails.

                              • 12. Re: If Function Problem

                                Oh.  Well then...did it look like a 'no' when viewed on the layout or in Data Viewer?

                                After you typed in the "no" value, what did the Code() watch return?

                                Is the field on the layout setup to 'select all contents on entry'?  Wondering if the old values are getting left behind when new ones are entered.

                                Is this field on the layout, where you are manually entering the info, in a portal?  Are there script triggers associated with the field?  Are there any auto-enter calculations?  Could you send some screen shots of the field definition, layout, and the Data Viewer results?


                                • 13. Re: If Function Problem

                                  Code() returned the same 1150010100089

                                  The field is on a portal and there are no Auto-enter calculation or Script triggers associated with it.

                                  Layout attached

                                  • 14. Re: If Function Problem

                                    Data Viewer attached

                                    1 2 Previous Next