- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2023 12:20 PM
I need to create a business rule to limit how high a user can change a integer value from the list view of a table. I had to convert this from a client script because I found out the users were changing directly from the list instead of the form itself. For some reason it's not showing the error as I'd expect.
I have the rule set to run Before an Update is made with these conditions.
Condition: current.u_sequence_priority.changes()
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2023 01:15 PM - edited ‎11-06-2023 01:16 PM
Add another log before the if to see if the script is getting triggered. If not then try moving the Condition to Filter Conditions, or adding it to the if statement. As written, the second part of your if statement is likely 500100 if the previous value was 500. You can log these too so you can see where it's going wrong. Also incorporating Clara's excellent suggestion to prevent the update when the error message is displayed, it would look something like this:
(function executeRule(current, previous /*null when async*/ ) {
gs.addInfoMessage ('BR running'); //temporary logging
var cursp = current.u_sequence_priority;
var presp = previous.u_sequence_priority;
gs.addInfoMessage('cur: ' + cursp + ' prev: ' + presp);
if (parseInt(cursp) > parseInt(presp) + 100) {
gs.addErrorMessage("Cannot increment the priority sequence by more than 100.");
current.setAbortAction(true);
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2023 06:57 PM
@phaug Since you have put the condition current.u_sequence_priority.changes() the BR script execution will only trigger if the value in u_sequence_priority field changes.
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2023 04:42 AM
Yes, that's why I said to take it out if the script is still not getting triggered. Try it without, then try adding it to the Filter Conditions or an if condition in the script. Double-check that this custom field name is exactly correct (space- and case-sensitive) and that it exists on the sn_customerservice_task table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2023 05:25 AM
Thanks, yeah it was a user error. I just caught that I spelled the variable name backwards. Once I removed the condition and updated the name it sends the error message as expected and changes the number back.