DFFS Set Field Value / Formatting

Home Forums Classic DFFS DFFS Set Field Value / Formatting

Viewing 3 reply threads
  • Author
    Posts
    • #8670
      DougMcCourt
      Participant

        Im trying set a rule for Editform for a list (On Save) that will set the value of a text field to the concatenation of {fielda}-{ID}. My permutation is I would like the result to be like X-0005, where value in ID is masked with leading zeros in the new field.

        I though about setting a rule where if {ID} < 10 have the rule set the value as {Fielda}-000{ID} and another rule if {ID} < 100 and so forth. Unfortunately, cant seem to figure out how to trigger a rule based on the value of {ID}. Anyone run in to this, or have any good idea? (I even tried to anticipate Alexanders’ cleverness by trying {Fielda}-{ID[0000]} like the way {timestamp} works!)

      • #8677
        Alexander Bautz
        Keymaster

          Hi,
          You cannot do this directly in the “set field value” section in the rule.

          If you want the ID to be generated on save, add a rule with the trigger “The form is saved”, and add “generateCustomID” in the “Run these functions / trigger these rules” field.

          Then you add this to the Custom JS section:

          function generateCustomID(){
          	var p = getFieldValue("ProgramType").charAt(0), id = spjs.dffs.data.thisItemID;
          	while(id.length < 4){
          		id = "0"+id
          	}
          	setFieldValue("IdNumber",p+"-"+id);
          }

          Please note that you must change the fieldname “ProgramType” and “IdNumber” to your own field names.

          Let me know how this works out.

          Alexander

        • #8691
          DougMcCourt
          Participant

            Absolutely perfect!

          • #8694
            Alexander Bautz
            Keymaster

              I’m glad it worked!

              Alexander

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