12 Replies Latest reply on Mar 27, 2013 2:17 PM by philmodjunk

    proper scripting for an   IF / Case / IsEmpty  ????  help

    CStovin

      Title

      proper scripting for an   IF / Case / IsEmpty  ????  help

      Post

           I have a Text field called,  "all_returned"  which is a drop down value list  with only "YES" as an option.  It also has the auto enter calculation option checked with the scripting :

           "YES" ;If (    IsEmpty   ( LINES::return_date ); Get ( CurrentDate )  )          <----- although this doesnt work

            

           What I want is   If  "YES"  gets entered into this field    "all_returned"   it will  Get Current Date and place that into another field called "individual_items_returned_date" , which is in a Line Item Portal ;   

      ONLY     if

           the "individual_items_returned_date"   field is empty, otherwise leave existing data.

            

           The    "individual_items_returned_date"     field is a pop up calendar date field that can be individually entered as items become returned.        The "all_returned" field allows a global date to be populated into "individual_items_returned_date"  for many items at once, while still allowing that field to operate independently.

           Can someone help me with either the script or calculation needed for this ?

           I am still learning how to write basic calculations and I seem to keep getting errors saying too many or not enough parameters are needed, and or an operator is required..... etc.  As well as not sure which function to use...

            

            

        • 1. Re: proper scripting for an   IF / Case / IsEmpty  ????  help
          philmodjunk
               

                    I have a Text field called,  "all_returned"  which is a drop down value list  with only "YES" as an option.  It also has the auto enter calculation option checked with the scripting :

               

                    "YES" ;If (    IsEmpty   ( LINES::return_date ); Get ( CurrentDate )  )          <----- although this doesnt work

               yes, that won't work. Remove this calculation from all_returned. You don't want the current date to appear in all_returned, you want it to appear in return_date.

               Find return_date in Manage | Database | Fields and give it this auto-entered calculation:

               If ( all_returned = "YES" ; get ( CurrentDate ) )

               Then make sure that the "do not replace existing value..." checkbox is selected so that it only enters the current date each time you create a new record in Line Items and then only if YES was selected in all_returned. Please note that any existing records will not enter a date in this field when all_returned receives the value "YES". Only records created after that event will automatically enter the current date.

          • 2. Re: proper scripting for an   IF / Case / IsEmpty  ????  help
            CStovin

                 Ok so I did this, and nothing happend.  Perhaps I left some key points out.

                 The all_returned field    belongs to the Work Order Table / Work Order Layout

                 The return_date field    belongs to the Line Items Table and is placed in a Portal with related items from Lines

                 The return_date field populates for each item in the portal

                 The Line Items is related to the Work Order via _kp_orders_id / _kf_orders_id

                 Product Item details auto enter into the Line Items portal via the relationship Products to Line Items

            • 3. Re: proper scripting for an   IF / Case / IsEmpty  ????  help
              CStovin

                   I tried changing the return_date field from a Text (with calculation option) to a straight calculation field and it replaced all return_date fields in the portal with the current date ( while overwriting the existing dates ).

                   I changed the return_date field back to a Text field with the calculation option and the checkbox checked,  and nothing happens, when "yes" is displayed in the all_returned field.

                    

              • 4. Re: proper scripting for an   IF / Case / IsEmpty  ????  help
                philmodjunk

                     Try creating a new record in line items with "yes" the value in All_returned and the settings as I specified.

                     Does the return_date field of the newly added record show today's date?

                     As I stated in my previous post:

                     Please note that any existing records will not enter a date in this field when all_returned receives the value "YES". Only records created after that event will automatically enter the current date.

                • 5. Re: proper scripting for an   IF / Case / IsEmpty  ????  help
                  CStovin

                       Ahh  Phil it works according to your solution but I don't think that is what I meant to ask for

                       Like you said, the return date will auto populate with the current date when I create a new line in the portal.

                       This will not work because as I am entering new information in the portal for people, the items will be leaving not returning the same day I am creating the portal items....so  that return date field needs to remain blank until either:

                       I individually enter a return date into the field - since some returned items come back on different dates or

                       I am returning all items at once with the condition that the all_return field contains the text "Yes"   When that condition exisits, than the remaining empty return_date fields become populated in the line items portal with the current date.

                  • 6. Re: proper scripting for an   IF / Case / IsEmpty  ????  help
                    CStovin

                         perhaps my tense is confusing for my naming convention

                         perhaps return_date should be    returned_date

                    • 7. Re: proper scripting for an   IF / Case / IsEmpty  ????  help
                      philmodjunk

                           That's why I very carefully spelled out the limitations of what I was suggesting. It's an inherent limitation of auto-entered calculations.

                           You'll need to use a script to update the line_item records with today's date.

                           Replace Field Contents [no dialog; Line_Items::return_date ; If ( Isempty ( line_items::return_date ) ; Get ( CurrentDate ) ; line_items::return_date ) ]

                           This will update all related records in Line_items to put today's date into the field if it is empty. If the field has a date, that date is left unchanged.

                      • 8. Re: proper scripting for an   IF / Case / IsEmpty  ????  help
                        CStovin

                             sorry I'm lost

                             I'm going to have to read this a couple times to see if I can figure it out.

                              

                        • 9. Re: proper scripting for an   IF / Case / IsEmpty  ????  help
                          CStovin

                               there needs to be 2 conditions which are true in order to place the current date

                               the Work Order::all_returned field needs to say "Yes",   and   the  Line Items::return_date  needs to be Empty.

                               the return_date field also has to be modifable so that other dates can be manually entered too.

                               If neither of these are true than leave existing data alone

                          • 10. Re: proper scripting for an   IF / Case / IsEmpty  ????  help
                            philmodjunk

                                 I understand, but you can just put a button on your layout that does this:

                                 Set field [Order::all_returned ; "Yes"]
                                 Replace Field Contents [....

                                 I could have put both conditions in the If function, but you only want this script to run when you select "Yes" so it's more efficient to not even run the script if the value in all_returned is not being set to "Yes"

                                 You can also use the OnObjectModify trigger on All_Returned and put an if step in the script the trigger performs:

                                 If [Order::All_Returned = "Yes"]
                                    Replace Field Contents [...
                                 End IF

                            • 11. Re: proper scripting for an   IF / Case / IsEmpty  ????  help
                              CStovin

                                   gotit   Sweet thanks for your Patience Phil:

                                   Work Order::all_returned       ->> plain text field no options selected

                                   Line Items::return_date     --->Date field no options selected

                                   "All returned Button etc." runs script All return

                                   ---------------------

                                   Show Custom Dialogue [ "All Equipment Items Returned ?"]                 ( button 2=Yes,  Button 3=No,   No default button  )

                                   If {Get (LastMessageChoice )=2

                                        Set Field [Order::all_returned;"Yes"]

                                        Replace Field Contents [no dialog; Line_Items::return_date ; If ( Isempty ( line_items::return_date ) ; Get ( CurrentDate ) ;                                       line_items::return_date ) ]

                                   End If

                                   If [Get (LastMessageChoice )=3]

                                       Set Field [ORDER::all_returned;"No"]

                                   End If

                                    

                                    

                                   thanks again Phil

                              • 12. Re: proper scripting for an   IF / Case / IsEmpty  ????  help
                                philmodjunk

                                     You might use:

                                     Show Custom Dialogue [ "All Equipment Items Returned ?"]                 ( button 2=Yes,  Button 3=No,   No default button  )
                                     If {Get (LastMessageChoice )=2
                                         Set Field [Order::all_returned;"Yes"]
                                         Replace Field Contents [no dialog; Line_Items::return_date ; If ( Isempty ( line_items::return_date ) ; Get ( CurrentDate ) ;line_items::return_date ) ]
                                     Else If [Get (LastMessageChoice )=3]
                                         Set Field [ORDER::all_returned;"No"]
                                     End If