UI action issue

pramn
Tera Guru

Hi Team , 

We have wrote a script  on UI action  below .

if (current.subcategory == '80') {

    if (current.u_approval_required == '1US') {

        alert('1US');

        current.state = 19;

        current.assignment_group = 'OTC COE US Manager 1';

 

    }

    if (current.u_approval_required == '2US') {

        alert('2US');

        current.state = 19;

 

        current.assignment_group = 'OTC COE US Manager 2';

 

    }

pramn_0-1691668256170.png

should go to pending approval 

pramn_1-1691668393442.png

 

 

when we click on UI action state should be Pending on approval state , but it is not happening 

could you please guide me ?

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@pramn 

your script is wrong.

Script seems to be server side since you are using current object and alert won't work there

Use gs.addInfoMessage() and use setDisplayValue to set the group

if (current.subcategory == '80') {
	if (current.u_approval_required == '1US') {
		gs.addInfoMessage('1US');
		current.state = 19;
		current.setDisplayValue('assignment_group', 'OTC COE US Manager 1');
	}
	if (current.u_approval_required == '2US') {
		gs.addInfoMessage('2US');
		current.state = 19;
		current.setDisplayValue('assignment_group', 'OTC COE US Manager 2');
	}
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

getting below error 

Function setDisplayValue is not allowed in scope sn_customerservice

Tushar
Kilo Sage
Kilo Sage

Hi @pramn 

 

something like this should help - 

 

if (current.subcategory == '80') {
    var approvalRequired = current.u_approval_required;
    var targetGroup = '';

    if (approvalRequired == '1US') {
        gs.addInfoMessage('1US');
        targetGroup = 'OTC COE US Manager 1';
    } else if (approvalRequired == '2US') {
        gs.addInfoMessage('2US');
        targetGroup = 'OTC COE US Manager 2';
    }

    if (targetGroup) {
        current.state = 19;
        current.setDisplayValue('assignment_group', targetGroup);
    }
}

 

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Regards,
Tushar