Change name of variable after approval
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi all,
I have a created form that allows the user to change the name of an assignment group name
When the user adds this to cart a request is sent to an approver and upon approval the name should change
I created a business rule to do this:
here are my variables:
But the name is not changing in the back end?
I do not want to do this from a flow so please do not suggest creating a flow
Please advise why its not changing the name in the back end
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
39m ago - last edited 38m ago
Aside from the obvious - making sure the variable names are correct, which you have excluded from the screenshots - add some logs to the script to see if it's running, and confirm the values used in each if condition and the GlideRecord. Trying triggering it after Update instead of async. I would move the first two if conditions to be Filter Conditions, and get rid of the third on line 12 as neither of those script variables will ever have the boolean value of false.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
36m ago
Hi @LJ_23 ,
If you are comparing to a sysid , its better to use the .getValue('cat_item') instead this will retrieve the sys_id .. On your line of code, seems you are comparing the catalog name to a sys_id.
Try the code below :
******************************************************************************************************************************
If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.
Best regards,
(function executeRule(current, previous) {
// Only run when approval changes to approved
if (!current.approval.changesTo('approved')) {
return;
}
// Only run for the specific catalog item (compare sys_id)
if (current.getValue('cat_item') !== 'b0bae485dbcab818b92c4dab0b9619f9') {
return;
}
// Get catalog variables (use Question names)
var groupSysId = current.variables.getValue('u_old_group_name');
var newName = (current.variables.getValue('u_new_group_name') || '').trim();
if (!groupSysId || !newName) {
return;
}
// Update assignment group name
var grp = new GlideRecord('sys_user_group');
if (grp.get(groupSysId)) {
grp.setValue('name', newName);
grp.update();
}
})(current, previous);
