Can I have an example of calling a jscript function from a rule

Home Forums Modern DFFS Can I have an example of calling a jscript function from a rule

Viewing 5 reply threads
  • Author
    Posts
    • #37444
      Marcus Khoo
      Participant

        When editing a form, I want to set a “single line of text” field with a substring of a second field whan that field is is changed.
        I was thinking that a Rule could pick up the event and a Custom JS function called by that rule would do it.

        Can you provide an example of such a Custom function called by a rule please?

        Thanks
        /Marcus

      • #37445
        Marcus Khoo
        Participant

          Doh! you have it already in the Examples. Sorry.

        • #37446
          Marcus Khoo
          Participant

            Spoke too soon. Don’t quite get the example.
            I want to trigger the update of a specific field when another changes and i want to do the same for twenty fields
            i.e.
            when A is changed, B is updated
            or
            when C is changed, D is updated
            or
            When E is changed, F is updated
            or
            etc.

            Thanks

          • #37449
            Alexander Bautz
            Keymaster

              Did you use the dffs_fieldChanged function from the Custom JS example thread?

              You should be able to do it something like this:

              function dffs_fieldChanged(fin, new_value, previous_value) {
                  switch (fin) {
                      case "fieldA":
                          setFieldValue("fieldB", new_value.substring(0, 10)); // 10 first characters of fieldA is written to fieldB
                          break;
                      case "fieldC":
                          setFieldValue("fieldD", new_value.substring(0, 10)); // 10 first characters of fieldA is written to fieldB
                          break;
                  }
              }
              

              Alexander

            • #37450
              Marcus Khoo
              Participant

                Thanks Alexander, but what calls this function? Is it called automatically whenever any field is changed?
                Thanks

              • #37451
                Alexander Bautz
                Keymaster

                  Yes

              Viewing 5 reply threads
              • You must be logged in to reply to this topic.