Home › Forums › General discussion › Count Values from Multiple Fields
- This topic has 4 replies, 2 voices, and was last updated 5 years, 9 months ago by Alexander Bautz.
-
AuthorPosts
-
-
February 19, 2019 at 23:07 #23888
Hi Alexander,
I hope you can help. My form has 12 fields that all have the same choice options: N/A, Submitted, In Progress, Approved, Declined. I have 2 number fields, RequestedCount and ReceivedCount.
Any field status with a value of Submitted or In Progress needs to be added in the RequestedCount
Any field status with a value of Approved or Declined needs to be added in the ReceivedCountOnce the 2 counts are equal, that would trigger a rule to send an email notification that all responses have been received. I have tried scripting this different ways, but haven’t been able to get anything to work. Thank you in advance for any help/assistance you can provide!
-
February 20, 2019 at 16:10 #23893
The RequestCount cones from the new form, so on the edit form, it would already be there. As I get the responses I need some way to know how many fields need an approval/decline so that when all are received I can fire another rule.
Thanks again!
-
February 20, 2019 at 21:40 #23903
In you NewForm Custom JS you must add this snippet (merge it with the existing function if you have used the same function name already):
function dffs_PreSaveAction(){ var arrOfFields = ["Status1","Status2","Status3"], count = 0; jQuery.each(arrOfFields,function(i,fin){ var v = getFieldValue(fin); if(v === "Submitted" || v === "In Progress"){ count += 1; } }); setFieldValue("RequestedCount",count); return true; }
Then add this to your EditForm Custom JS:
function dffs_PreSaveAction(){ var arrOfFields = ["Status1","Status2","Status3"], count = 0; jQuery.each(arrOfFields,function(i,fin){ var v = getFieldValue(fin); if(v === "Approved" || v === "Declined"){ count += 1; } }); setFieldValue("ReceivedCount",count); if(getFieldValue("RequestedCount") === String(count)){ // Same number - trigger email configured in E-Mail and Print tab by ID: spjs.dffs.processEmailTemplate("testMail"); } return true; }
Change the fields “Status1”, “Status2” etc. to match your field names.
Let me know how this works out.
Alexander
-
February 21, 2019 at 23:30 #23922
Alexander, thank you so much! This is awesome! I did have to make one minor change, for some reason it wasn’t saving the form, so I just changed the function name, and set up a rule to call the function when the form is saved.
-
February 22, 2019 at 00:13 #23924
I’m glad you got it running – and thank you for your donation!
Best regards,
Alexander
-
-
AuthorPosts
- You must be logged in to reply to this topic.