Approval Script Getter Error

Bill_Collins
Mega Guru

Friends,  Where is my error?

 

 

 

answer = [];

var approvalGroupId = current.variables.site_or_library.u_application_owner_approval_group.sys_id.toString();
gs.info('### approvalGroupId is ' + approvalGroupId);
var approvalGroupName = current.variables.site_or_library.u_application_owner_approval_group.getDisplayValue();
gs.info('### approvalGroupName is ' + approvalGroupName);


var createdUser = current.sys_created_by;
gs.info('### createdUser is ' + createdUser);
var openedUser = current.opened_by;
gs.info('### openedUser is ' + openedUser);
var requestedUser = current.variables.vset_user;
gs.info('### requestedUser is ' + requestedUser);


var create = gs.getUser().getUserByID(createdUser).isMemberOf(approvalGroupName);
gs.info('### Created By isMember ' + create);
var open = gs.getUser().getUserByID(openedUser).isMemberOf(approvalGroupName);
gs.info('### Opened By isMember ' + open);
var request = gs.getUser().getUserByID(requestedUser).isMemberOf(approvalGroupName);
gs.info('### Requested By isMember ' + request);

if (create || open || request) {
	current.work_notes = 'The Requester, person Creating, or person Opening this request is an approver of this item.  Hence, the Owner Approval is skipped.';
	answer.push();
	}
else {
	answer.push(current.variables.site_or_library.u_application_owner_approval_group.sys_id.toString());
	}

 

 

4 REPLIES 4

Bert_c1
Kilo Patron

I suggest you post more context, such as where does your code reside? What are steps-to-reproduce? Once more context is provided, you will get responses that can assist you with your problem.

It is an approval script from a workflow approval activity. 

  • Variable
    • vset_user.  Reference variable to sys_user.
    • site_or_library.u_application_owner_approval_group.  Dot walked reference to sys_user_group as field on a CI class record. 

So what are you expecting and where does it break?

Only thing I would recommend is to use the getValue function when getting info off the current variable.

var createdUser = current.getValue('sys_created_by');
gs.info('### createdUser is ' + createdUser);
var openedUser = current.getValue('opened_by');
gs.info('### openedUser is ' + openedUser);

 likely something similar for your vset_user

var requestedUser = current.variables.vset_user.toString();
gs.info('### requestedUser is ' + requestedUser);

 

Reference:  https://www.servicenow.com/community/developer-blog/tnt-the-importance-of-using-quot-getvalue-quot-w... 

 

HTH & Good Luck

Ankur Bawiskar
Tera Patron
Tera Patron

@Bill_Collins 

can you explain along with screenshots what's your business requirement?

Seems it's an approval activity script so which user and group should be set for approval?

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