2 Replies Latest reply on Jun 4, 2012 1:46 AM by user14040

    Script Question with Auto Insert and date

    user14040

      Title

      Script Question with Auto Insert and date

      Post

      Hi

       

      Trying to create a script that will auto insert text on certain dates. ( Still learning how to create scripts on my own)

      What I want to do is auto insert "Pending" into a drop down field on dates less than 15 (Insert "Pending" between 6/1/2012 to 6/14/2012)

       

      And then what I want to do is auto insert "Yes" in drop down field on dates 15th and above.

       

      This is the script I have and it seems to work but I wont really now until the 15th.  Right now it is inserting 'Pending" when a new record is created.  But will it insert Pending on the 15th and above?

       

      My Script:

      New Record/Rrequest

      If[Get(CurrentDate) ≥ "15"]

      Insert Text[Select;Glassware::ChargeForService; "Pending"]

      Commit Record/Request[Skip data entry validation;No dialog]

      Go to Next Field

      Else If[Get ( CurrentDate )   ≤   "15"]

      Insert Text[Select;Glassware::ChargeForService; "Yes"]

      Commit Record/Request[Skip data entry validation;No dialog]

      Go to Next Field

      End If

       

      Just want to know is if this script will do what I need it to do or do I have to change it.  

       

      Thanks

        • 1. Re: Script Question with Auto Insert and date
          Sorbsbuster

          At first I thought you were retrospectively trying to update the status on existing records, depending on the date in a field.  But when I got to the end I believe that you are trying to auto-enter either a 'Pending' or 'Yes' depending on the date that you create the record.  if that is the case then you don't need a script.

          Go to the field definition of the ChargeForService field.  Click 'Options', and go to the Auto-enter tab.  Near the bottom, check the 'Calculated Value' box, and specify this as the calculation:

          Case (

          Day ( Get ( CurrentDate ) ) ≥ 15 ; "Pending" ;

          "Yes"

          )

          That will enter 'Yes' up to the 14th of the month, and 'Pending' from the 15th on.

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

          There are a few problems with the concept of your script, anyway:

          New Record/Request

          (Would not have entered the correct value if the user just created a record from the menu, or used Cmd-N.  It would only work if this was the only way all new records could be created)

          If[Get(CurrentDate) ≥ "15"]

          (Dates are just serial numbers to FM, so '15' is the 15 January 0001, so it will always evaluate as 'True'.)

          Insert Text[Select;Glassware::ChargeForService; "Pending"]

          Commit Record/Request[Skip data entry validation;No dialog]

          Go to Next Field

          (Can't see why you want the script to go to the next field.  You are trying to set the same field in the next step.  You want an 'Else' step here, to tell FM what to do if the first condition isn't met.)

          Else If[Get ( CurrentDate )   ≤   "15"]

          (Make this just as 'Else'.  The date comparison has the same problem as before.)

          Insert Text[Select;Glassware::ChargeForService; "Yes"]

          (The 'Set Field' script step is probably a better one to use, although in this instance 'Insert Text would have worked.)

          Commit Record/Request[Skip data entry validation;No dialog]

          Go to Next Field

          (Not needed)

          End If

          • 2. Re: Script Question with Auto Insert and date
            user14040

            I really thought I got this on my own Thank you for your help.

            The reason I used Go to Next field was because when I clicked on the button I created with the script It stayed at the field Glassware::ChargeForService with the menu active. What I needed to do was to be able to commit the reccord then have it go to the next field which is the field I had set as the default field in set tab order.  

            Which did work but I see my thoughts were completely wrong.  Yours looks to be the better choice.

             

            Thanks