- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2023 03:54 AM - edited 04-04-2023 03:56 AM
Hi!
I have created an integer calculated field using a Business Rule so that whenever a value changes the Total field should also update. The problem is that the team also want to see of the Total is 0. I can set the Default Value of the field to 0 but this will affect there reporting as the UAT work is done at the end of the process.
My business rule is:
(function executeRule(current, previous /*null when async*/ ) {
// u_number_of_uat_errors_1 // Internal Errors 1
// u_uat_errors_2 // Internal Errors 2
// u_uat_errors_3 // Internal Errors 3
// u_uat_errors_4 // Internal Errors 4
// u_number_of_uat_errors // Total Number of UAT Errors
//Add all the time fields together
var totalUat = parseFloat(current.u_number_of_uat_errors_1 + current.u_uat_errors_2 + current.u_uat_errors_3 + current.u_uat_errors_4);
//Check if new total is different to old total
if (totalUat != current.u_number_of_uat_errors) {
//Update total time field
current.u_number_of_uat_errors = totalUat;
current.update();
}
})(current, previous);
Is it possible to add all the fields and if the result = 0 then this gets entered?
Any assistance greatly received
Regards
Dave
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2023 04:10 AM
Hi @Dave105 ,
Yes, it is possible to update the code to handle a total of 0. You can modify the business rule to check if the total value is not null or undefined and if it is 0, then update the field with the value of 0. Here's the updated code:
(function executeRule(current, previous /null when async/ ) {
// u_number_of_uat_errors_1 // Internal Errors 1
// u_uat_errors_2 // Internal Errors 2
// u_uat_errors_3 // Internal Errors 3
// u_uat_errors_4 // Internal Errors 4
// u_number_of_uat_errors // Total Number of UAT Errors
//Add all the time fields together
var totalUat = parseFloat(current.u_number_of_uat_errors_1 + current.u_uat_errors_2 + current.u_uat_errors_3 + current.u_uat_errors_4);
//Check if new total is different to old total
if (totalUat !== current.u_number_of_uat_errors || totalUat === 0) {
//Update total time field
current.u_number_of_uat_errors = totalUat;
current.update();
}
})(current, previous);
If my response was helpful in resolving the issue, please consider accepting it as a solution by clicking on the ✅Accept solution button and giving it a thumbs up 👍. This will benefit others who may have a similar question in the future.
Thank you!
Ratnakar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2023 04:10 AM
Hi @Dave105 ,
Yes, it is possible to update the code to handle a total of 0. You can modify the business rule to check if the total value is not null or undefined and if it is 0, then update the field with the value of 0. Here's the updated code:
(function executeRule(current, previous /null when async/ ) {
// u_number_of_uat_errors_1 // Internal Errors 1
// u_uat_errors_2 // Internal Errors 2
// u_uat_errors_3 // Internal Errors 3
// u_uat_errors_4 // Internal Errors 4
// u_number_of_uat_errors // Total Number of UAT Errors
//Add all the time fields together
var totalUat = parseFloat(current.u_number_of_uat_errors_1 + current.u_uat_errors_2 + current.u_uat_errors_3 + current.u_uat_errors_4);
//Check if new total is different to old total
if (totalUat !== current.u_number_of_uat_errors || totalUat === 0) {
//Update total time field
current.u_number_of_uat_errors = totalUat;
current.update();
}
})(current, previous);
If my response was helpful in resolving the issue, please consider accepting it as a solution by clicking on the ✅Accept solution button and giving it a thumbs up 👍. This will benefit others who may have a similar question in the future.
Thank you!
Ratnakar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2023 04:33 AM
Thank you so much, for the full and speedy response!