The CreatorCon Call for Content is officially open! Get started here.

Generating tasks from a list collector in a Service Catalog Item

Pat Slattery
Mega Expert

Morning!

I am looking to generate tasks based on selection of values from a list collector that I have added to a catalog item. 

I.E.> if multiple values are selected, generate tasks out to those teams 

Selections == Workday;OKTA;Sailpoint

Workday > Send task to workday services 

OKTA > Send task to Okta Servicesa

Sailpoint > Send task to Sailpoint Services 

 

Currently i have 6 list collector fields that contain different reference qualifiers limting data points coming from the applications table in CMDB. The values from these list collectors then will need to generate SCTASKS when selected to the assignment group indicated on the CI record. 

 

Looking for advice on the best practices of how to achieve this. 

 

Thank you in advance!

1 ACCEPTED SOLUTION

Mark Stanger
Giga Sage

You'll want to use a 'Run script' activity in your request item workflow to do this.  The script will iterate through the values in the list collector variable and then create an 'sc_task' record for each one.

// Create 'sc_task' records for each item in the list collector var
var options = current.variables.MY_LIST_COLLECTOR_VAR_NAME;

// Iterate through the options
for (i=0; i < options.length; i++) {
    // Query for the current CI
    var ci = new GlideRecord('cmdb_ci');
    ci.get(options[i]);

    // Create a new task record for the current CI
    var sct = new GlideRecord('sc_task');
    sct.initialize();
    sct.short_description = 'Task for ' + ci.name;
    sct.assignment_group = ci.assignment_group; // Make sure this field name is correct!
    sct.request_item = current.sys_id;
    sct.insert();
}

View solution in original post

10 REPLIES 10

Mark, 

Additional question that I did have was around passing variables from the RITM to the SCTASK's that are being created.

Since these are being auto generated, I assume that I will need to state these in the task generation code where the asssignment group is being set, however that is not being set from the same location.

 

Any advice here?

 

Thanks again!

Hey Mark,

 

Thank you for sharing this code 🙂

How about updating CI records? This code is actually creating the Catalog Tasks based on the list collector, How can this be accommodated if it has to check for a CI record based off the CI sys_id and update certain information say Operational status?

 

Could you please provide a code to update the Operational Status based on the CI selected in the list collector?

 

Thanks in Advance.

Praveen.

Muktha R
Kilo Explorer

Hi Mark,

Same requirement as above but some add on,

Before generating tasks based on the list collector variable. It should have approval activity(user approval based on list collector variable. for ex: workday--->user1, Okta----->user2 and so on).

It should generate tasks only for the approved records not for the rejected records.

Please help me on this.

Hi Muktha, 

 

Sorry for the late response. 

You can add an Approval Activity by querying the approval and if approved generate the task. 

Same way for Rejected and cancel the request. 

You can modify it either by using flow designer or Workflow Editor. 

Regards, 

pK

William Course1
Tera Guru

Thanks for the info, Mark!  I used it on a list collector based on the the sys_user table and found that it didn't work properly for me until I modified the first line to:

var options = current.variables.MY_LIST_COLLECTOR_VARIABLE_NAME.toString().split(',');

Just in case anyone else runs into the same issue!