Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Delegate User script for approval,assignment,all notification

Divyesh Thakur
Tera Contributor

I Created a Delegate catalog Item to request Delegations and I attached one Workflow. In this work flow I used run script to create delegate record automatically. But I want the functionality to check the approval, assignment, all notification according to the choice which the user selects from the catalog item. I have given the delegation type as multiple choice.
Run script code in Workflow:-

if(current.variables.delegation_type=='Approvals')
{
var del = new GlideRecord('sys_user_delegate');
g_form.setValue('approvals', true);
del.addQuery('user',current.variables.u_requested_for);
del.query();
if(!del.next())
{
del.initialize();
del.user = current.variables.u_requested_for;
del.delegate = current.variables.assigned_delegate;
del.starts = current.variables.start_date;
del.ends = current.variables.end_date;
del.approvals = current.variables.Approvals;

del.insert();
}
else
{
del.user = current.variables.u_requested_for;
del.delegate = current.variables.assigned_delegate;
del.starts = current.variables.start_date;
del.ends = current.variables.end_date;
del.approvals = current.variables.Approvals;
//del.assignments = current.variables.Assignments;
//del.notifications = current.variables.All_notifications;
del.update();
}
}
else if(current.variables.delegation_type=='Assignments')
{
g_form.setValue('assignments', true);
del.addQuery('user',current.variables.u_requested_for);
del.query();
if(!del.next())
{
del.initialize();
del.user = current.variables.u_requested_for;
del.delegate = current.variables.assigned_delegate;
del.starts = current.variables.start_date;
del.ends = current.variables.end_date;

del.assignments = current.variables.Assignments;
del.insert();
}
else
{
del.user = current.variables.u_requested_for;
del.delegate = current.variables.assigned_delegate;
del.starts = current.variables.start_date;
del.ends = current.variables.end_date;
del.assignments = current.variables.Assignments;
del.update();
}
}



0 REPLIES 0