Count number of fields with specific value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2023 12:46 AM
Hello!
I have a custom table with 4 tabs:
- Summary
- Tab 1
- Tab 2
- Tab 3
In each of the tab (Tab 1, Tab 2, Tab 3) there are Status custom fields.
In the summary tab, I want to show the number of Status fields that are set to Completed.
For example:
Tab 1 (3/5)
Tab 2 (0/2)
Tab 3 (2/7)
Is this possible?
Please help!
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2023 12:58 AM
Yes, it's possible, but a bit annoying to do.
Basically you need multiple client scripts if you want it to be dynamic.
For each field you'd need a onChange client script which checks every status field and then updates the summary count.
For example
onChange client script for any of the fields:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var count = 0;
var fields = ["x1","x2","x3","x4"];
for(var i in fields){
if(g_form.getValue(fields[i]) == 'status_value'){
count++;
}
}
g_form.setValue('xsummary', count);
}
Basically you just list all the fields with the status to check on the fields array. The for loop loops through them and if the value for the field is "status_value" (change this to the value you want to use) then the count is updated. At the end you set the count as the value for the summary field.
You need to set this exact same onChange script for each of the status fields that are getting updated to make sure it's run each time any of the fields are updated.