Check multiple fields with 1 rule?

Forums Classic DFFS Check multiple fields with 1 rule?

Viewing 5 reply threads
  • Author
    Posts
    • #9284
      Bloodlvst
      Participant

      Just wondering if this is possible.

      So I already have one rule that states if I set a field to one of 2 options, that it makes 5 other fields required. I was looking into making an alert with a 2nd rule, but it looks like I’d need to make 5 different rules for each field to check if it’s empty.

      Is there any way to do this in the “rules” section, or will I need to create a custom JS function for the rule to check true/false? If so that’s fine, just want to stick with rules if possible.

      Thanks!

    • #9297
      Alexander Bautz
      Keymaster

      Hi,
      Can you tell me some more about the alert? – how is it supposed to trigger?

      If we must use a custom function, this can be written in the custom js textarea, and called from a function with a trigger “custom javascript function”.

      If you have some more details, I’ll help you with the function.

      Alexander

    • #9312
      Bloodlvst
      Participant

      Sure thing! The trigger is:

      If field “Status” is equal to “Resolved|Closed”
      Triggers on field change

      The rule makes the following fields mandatory:
      Primary Issue
      Secondary Issue
      Service Category
      Root Cause
      Ownership

      Currently, no matter whether those fields are empty, it pops up the alert if you changes the “Status” field to “Resolved” or “Closed”. Of course this makes sense based on the rule, but I’m looking to trigger the alert only if “Status” is changed and any of the 5 fields are empty (without making 5 more triggers).

      Let me know if you need any more info, and thanks so much for offering to help with the function if necessary! 🙂

    • #9359
      Alexander Bautz
      Keymaster

      Sorry for the delay. Here is a solution that involves adding one function to the “Custom JS” textarea:

      In you rule, add this function name in the “Run these functions / trigger these rules” field:

      checkRequiredFields

      Then add this function to the “Custom JS” textarea:

      function checkRequiredFields(ruleID){
      	var a = true;
      	if(ruleID === "myTestRule"){
      		var arr = ["Field1","Field2","Field3"];
      		spjs.$.each(arr,function(i,f){
      			if(getFieldValue(f).length === 0){
      				a = false;
      				return false;
      			}
      		});
      		if(!a){
      			alert("You must fill in all fields");
      			// Optionally use the DFFS alert
      			//spjs.dffs.dlgBox("You must fill in all fields",true);
      		}
      	}
      }

      You must change “myTestRule” to the “friendlyName” of your rule, and “arr” to contain your fields.

      Let me know how this works out.

      Alexander

    • #9379
      Bloodlvst
      Participant

      Hey Alex!

      I’m getting the following error when I call the function:

      screenshot

      NEVERMIND! I’m an idiot who didn’t use the internal field name. All good now! 😀

      • This reply was modified 8 years, 5 months ago by Bloodlvst.
    • #9384
      Alexander Bautz
      Keymaster

      I’m glad you figured it out.

      Alexander

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