After approving the case, hr task should assign to same approver

Suzy
Tera Contributor

Hi All,

 

I have a "CASE" which is assigning to a GROUP and any member in the group can approve the case, Now I need to assign a "TASK (HR Task)" to the same approver who approved the CASE earlier.

I have used the Create Task activity and used the Advanced scripting and written the below script and it is not waiting for completion of task and not triggering the task assigned to same approver.

Please suggest

var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('document_id', current.sys_id);
gr.query();
if(gr.next())
{
task.assigned_to = gr.approver.name;
}
2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Suzy 

your script to assign user is wrong

update as this

are you using workflow for creating task? if yes then there is Wait for completion checkbox on Create Task activity

var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('document_id', current.sys_id).addOrCondition('sysapproval', current.sys_id);
gr.query();
if(gr.next())
{
	task.assigned_to = gr.approver;
}

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

Hi Ankur,

 

Thanks for your reply.

 

It did work with below script.

var gr=new GlideRecord('sysapproval_approver');
gr.addEncodedQuery('sysapproval='+current.sys_id+'^state=approved');
gr.query();
if(gr.next())
	{
		
		task.assigned_to= gr.approver;
	}