- 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 01:02 PM
Hi @phaug ,
One thing that you might want to add to your script is a current.setAbortAction(true); after your error message, so that the user is not able to do to the modification.
But what exactly is not working as you expected? Is your field type integer?
If that helps please mark my answer as correct / helpful!
And if further help is needed please let me know
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2023 01:07 PM
Thanks, I did add that to the script.
I'd expect to see an error if I increased the number in the field by over 100. But, I'm still able to change the number from the list view, increasing the field by over 100 without the error message appearing. And yes, the field type is an integer.
- 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 01:32 PM - edited ‎11-06-2023 01:44 PM
Thanks, I tried that and it doesn't appear to be working. I'm not seeing anything in the logs. Could it be the condition I have listed above the script?
Condition: current.u_sequence_priority.changes()