Change name of variable after approval

LJ_23
Tera Contributor

Hi all,

I have a created form that allows the user to change the name of an assignment group name

LJ_23_2-1769191076373.jpeg

When the user adds this to cart a request is sent to an approver and upon approval the name should change 

LJ_23_4-1769191302571.jpeg

I created a business rule to do this:

LJ_23_3-1769191287751.jpeg

LJ_23_5-1769191332100.png

 

here are my variables:

LJ_23_1-1769191064004.jpeg

 

But the name is not changing in the back end?

LJ_23_0-1769191053940.jpeg

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

2 REPLIES 2

Brad Bowman
Kilo Patron

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.

DGAJ
Giga Guru

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);

 

DGAJ