5 Replies Latest reply on Nov 10, 2015 8:19 AM by Abingdon

    Script setting a variable with the contents of a field

    Abingdon

       

      Hi All,

      I am writing a script to set a global variable with the contents of a field using the OnObjectEnter script trigger as I need to capture the current value in that field before it is changed.

      There are four fields on the layout to which I want to apply this trigger.  It works fine when the fields are formatted as drop-down lists, but not when they formatted as drop-down menus.  I understand that the script trigger behaves differently depending on whether it is applied to a drop-down list (the script will run first) and a drop-down menu (the script runs after a value is selected).  I believe I need to pass the value in the field as a parameter, Get(ScriptParameter) but I am damned if I can figure out how.

      The drop-down list script is:

      Set Variable [$$Content; Value: GetField (“MyActualFieldName”)]

       

      So far for the drop-down menu version I have:

      Set Variable [$$Content; Value: Get (ScriptParameter)]

       

      I attach that to the field with the Script Parameter as follows:

      GetField(GetFieldName(Evaluate(Get(ActiveFieldName))))

       

      I get a question mark returned as the data.  Clearly not doing it right.

      As mentioned I need to use this script on multiple fields so a single script for all would be good.

      Many thanks as always.

       

      Abingdon

       

       

       

        • 1. Re: Script setting a variable with the contents of a field
          jbrown
          I believe I need to pass the value in the field as a parameter, Get(ScriptParameter) but I am damned if I can figure out how.

          You can write the script parameter when choosing the script.

          Screen Shot 2015-11-10 at 6.04.20 AM.png

          I put the field I want passed into the script parameter section. That will pass the fully qualified name into the script. Then I believe you can do GetField ($Content).

           

          you can simply skip a few steps by putting

          GetField (GetFieldName ( YOURTABLE::YourField) )  in the script parameter section. If possible, I'd always commit the record so that the new data is put in the field when the trigger is run. The function Get(ActiveFieldContents) wouldn't work in this case because the record has been committed.

           

          As mentioned I need to use this script on multiple fields so a single script for all would be good.

          Just use this same method for every field you want and it will work every time. The parameter still needs to be unique to the field in your case.

          • 2. Re: Script setting a variable with the contents of a field
            Abingdon

            Hi Jeremy,

             

            Many thanks for your reply.  I am not sure I am following you very well.

             

            What should be the actual script step(s) be before I put the Script Parameter in?

            I have put GetField(GetFieldName("MyTable::MyFieldName"))  as my parameter but I don't see how this would  pass the contents of the field to my $$Content variable.

             

            I am not aiming to change any data in the field, I just want to capture the existing data into the $$Content variable.

             

            The other thing is that the script still only fires after data is selected from the drop-down menu is selected, which is too late to capture the existing data before it may be changed.

             

            Forgive me if I am being slow.

            • 3. Re: Script setting a variable with the contents of a field
              Abingdon

              Sorry, my fault, I left out the GetScriptParameter in my script step.

               

              Now all I need is a way to pass the name of the field dynamically rather than by its literal name.

               

              Thank you for your help once again.

              • 4. Re: Script setting a variable with the contents of a field
                SteveMartino

                Couldn't you simple just use OnObjectEnter with this script:

                Set Variable [$$ActiveField; Value: Get(ActiveFieldContents)]

                 

                To check, in a sample I put this script trigger on every field and created a new field called sample. I also added a second line to the script,

                Set Field [Table::Sample; $$ActiveField]

                As I click into any field, the sample field displayed the content of the field I clicked into

                • 5. Re: Script setting a variable with the contents of a field
                  Abingdon

                  Hi Steve,

                   

                  Thank you for your help. Yes, this does collect the data but only if the field is formatted as a drop-down list.  It does not work if the field is a menu.  The Variable is empty.

                   

                  On a slightly different note, but related to all this, do you know how to set the full name of a related field into a variable?

                  i.e. RelatedTable::FieldName   I can only get a variable to set with the field name if it's in the same table.

                   

                  Thanks again.

                  Abiingdon