
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2016 12:28 PM
Hello,
I have a request to create multiple tasks from a workflow script depending on the items assigned to a user. There is no set amount of tasks that needs to be created, could be 1, 2 or 3, depends on the assets assigned. I am having a hard time querying the items assigned to the user to be able to create a task for each one.
Basically, I am querying a table (Master) to see how many master records are assigned to the user and then create a task per record found. An Assets table is referenced form the Master table which contains the assignment group that the tasks need to be assigned to.
My goal is to query the Master table, identify how many master records are assigned to the user, and create tasks for each master record found for the user and assign it to the group in the assets table.
This is what I've been working on but this isn't working as expected, it doesn't create the tasks...
Workflow script:
var assnt_group = [];
var RequestedFor = current.variables.requested_for;
var gr = new GlideRecord('u_nerc_cip_access');
gr.addQuery('u_contact_name', RequestedFor);
gr.query();
var grps = 0;
while(gr.next()) {
assnt_group.push(gr.u_asset.u_contractor_pra_contact_group + "");
}
//Then you can create a task for each assignment group
for(var i=0; i < assnt_group.length; i++ ) {
try{
var tsk = new GlideRecord('sc_task');
tsk.initialize();
tsk.u_access_requested_for = current.variables.u_term_name;
tsk.due_date = current.due_date;
tsk.request_item = current.sys_id;
tsk.parent = current.sys_id;
//tsk.assignment_group = acc.u_asset.u_contractor_pra_contact_group;
tsk.short_description = "Enter Contractor / Vendor's Valid Background Check Date";
tsk.description = "1.Enter the contractor / vendor's valid NERC-CIP background check date. (This may require contacting the vendor to attest to a new background check if the current one is older than 6.5 years.)"+"\n";
tsk.description += "2.Close the Task.";
tsk.state = 1;
tsk.u_bg = 'true';
tsk.u_business_reason = current.variables.u_business_reason;
task.assignment_group = assnt_group[i];
task.insert();
} catch(e) {
gs.log("Exception in task creation " + e);
}
}
Any help is truly appreciated!
Thank you,
Yeny
Solved! Go to Solution.
- Labels:
-
Service Mapping

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2016 01:31 PM
You defined the object and called it 'arr', but later tried to use it as arrayUtil.
Change them all to one or other and you should be fine.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2016 01:45 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2016 01:51 PM
Yeny,
Try converting sys_id to a string while pushing it into an array like this
assnt_group.push(gr.u_asset.u_contractor_pra_contact_group.toString());
Thanks,
Abhinay
PS: Hit like, Helpful or Correct depending on the impact of the response

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2016 02:04 PM
Hi Abhinay,
This worked! Thank you so much! The script created the tasks that were needed and did not create any other tasks for the same group.
Thank you!!!
Yeny

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2016 02:05 PM
Thank you for all your help with this issue Chuck! I truly appreciate it!!
Yeny

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2016 02:07 PM
Glad you got it working!