Various approvers - advanced approval script

Hannah C
Giga Expert

Hi there!

I am trying to write a script on an Approver activity in a workflow. On the catalog item, a user will select a group on the variable GroupName. If the group has a manager, I want the group manager to be the approver. If there is no group manager, I want the Business Service Owner to be the approver. If the group does not have a manager or a Business Service Owner, I have 3 specific people I want to be the approvers but only one needs to approve. Here is what I have been trying and it does work when the group has a manager but after that it is not working

 

var answer = [];

if (current.variables.GroupName.manager != '')
{answer.push (current.variables.GroupName.manager.sys_id.toString());}

else if (current.variables.GroupName.business_service_ownerDONOTUSE != '')
{answer.push(current.variables.GroupName.business_service_ownerDONOTUSE.sys_id.toString());}

else
{answer.push('13ece655db949340b3613caf9d9619f6');
answer.push('5bec2a55db949340b3613caf9d961948');
answer.push('5fec2a55db949340b3613caf9d961919');}

 

On the last else statement, those are the sys ids of the three people to be the approvers if no manager and no business service owner

17 REPLIES 17

How do you confirm which table it is running on?

Check the workflow properties of this workflow. It should have the table name


Please mark this response as correct or helpful if it assisted you with your question.

Ok thank you! I confirmed it is on the Requested Item workflow however it still isn't working 😕

Can you run the below in you Approval - User script and let me know, what you see in the System logs

 

gs.log('+++++Manager is+++++++++'+current.variables.GroupName.manager.toString());

gs.log('+++++Service Owner+++++++++'+current.variables.GroupName.business_service_ownerDONOTUSE.toString());

var answer = [];

if (current.variables.GroupName.manager != '')
{

gs.log('+++++Manager Condition+++++++++');

answer.push(current.variables.GroupName.manager.toString());

}

else if (current.variables.GroupName.business_service_ownerDONOTUSE != '')
{

gs.log('+++++Business Service Condition+++++++++');

answer.push(current.variables.GroupName.business_service_ownerDONOTUSE.toString());

}

else
{

gs.log('+++++Last Condition+++++++++');

answer.push('13ece655db949340b3613caf9d9619f6');
answer.push('5bec2a55db949340b3613caf9d961948');
answer.push('5fec2a55db949340b3613caf9d961919');

}


Please mark this response as correct or helpful if it assisted you with your question.

There are three errors that say: java.lang.NullPointerException: java.lang.NullPointerException: