Copying Data from one Catalog Task to another Catalog Task

Jake Golden
Tera Expert

Hello,

 

I am currently trying to pull information from task 1 to default into task 2. The fields I am targeting are associated with the Configuration Item table and my task are Catalog Tasks. 

For example, task 1 requires the user to select an asset in the Configuration Item table. Once the item has been selected, there are two additional field, 'owned by' and 'Computer Name'. The additional fields will be filled out and once the task is completed, those fields write back to the CI table. Upon completion of task 1, task 2 is auto generated from the workflow. Now on task 2 I would like to auto populate the CI value, owned by, and computer name that had been entered on task 1.

 

 

1 ACCEPTED SOLUTION

Mahendra RC
Mega Sage

Hello Jake,

So when you are creating your Task 1 set the Order field of that task as 100 and you can use the below script in your Create Catalog Task activtiy for Task 2:

var scTask = new GlideRecord("sc_task");
scTask.addEncodedQuery("request_item=" + current.getUniqueValue() + "^state=3^order=100");
scTask.query();
if(scTask.next()){
	task.cmdb_ci = scTask.getValue("cmdb_ci") 
	task.short_description = scTask.getValue("short_description");
	task.u_owned_by = scTask.getValue("u_owned_by"); //CHECK YOUR FIELD NAME AND REPLACE IF REQUIRED
	task.u_computer_name = scTask.getValue("u_computer_name"); //CHECK YOUR FIELD NAME AND REPLACE IF REQUIRED
	task.order = 200;
}

Please mark my respsone as helpful/correct, if it answer your question.

Thanks

View solution in original post

4 REPLIES 4

MrMuhammad
Giga Sage

Hi @Jake Golden

Below is the sample script that you can use.

Inside if(grTask.next()){...} you can add fields to copy from ctask 1 to ctask 2. 

task represents ctask2 and grTask represents ctask1.

e.g. if you want to copy assigned_to so you would do something like this

task.assigned_to = grTask.assigned_to

// Set values for the task in this script.  Use the variable 'task' when setting additional values.
// Note: This script is run after the task values are set using the Fields, Template or Values you have specified.
//
// For example:
//     task.short_description = current.short_description;

var grTask = new GlideRecord("sc_task");
grTask.addQuery("sys_id", current.getValue('sys_id'));
//grTask.addQuery('short_description', "SHORT DESCRIPTION OF FIRST TASK");
grTask.query();

if(grTask.next()){
	task.cmdb_ci = grTask.cmdb_ci; 
	task.short_description = grTask.short_description;
	//add more fields here
}

Please try and let me know if you face any issues.

Please mark this helpful/correct, if applicable.

Regards,

Muhammad

Regards,
Muhammad

 

Thank you for the reply Muhammad. I tried copying the above script and only used the script below in the if() statement

task.short_description = grTask.short_description;

I was unsuccessful in pulling any data. 

 

Another hole I dug into was using the scratchpad. Is it possible to delay when this script runs? As we see: 

// Note: This script is run after the task values are set using the Fields, Template or Values you have specified.

 

If I can delay the task 1 script to run after closer of task, I could accomplish this through the scratchpad. But currently the scratchpad will only capture information at opening of ticket as that is when the script runs. 

 

I am more than happy to continue on the path you suggested just now, but figured I would ask this question as well for another possible solution.

 

thanks,

Jake

Mahendra RC
Mega Sage

Hello Jake,

So when you are creating your Task 1 set the Order field of that task as 100 and you can use the below script in your Create Catalog Task activtiy for Task 2:

var scTask = new GlideRecord("sc_task");
scTask.addEncodedQuery("request_item=" + current.getUniqueValue() + "^state=3^order=100");
scTask.query();
if(scTask.next()){
	task.cmdb_ci = scTask.getValue("cmdb_ci") 
	task.short_description = scTask.getValue("short_description");
	task.u_owned_by = scTask.getValue("u_owned_by"); //CHECK YOUR FIELD NAME AND REPLACE IF REQUIRED
	task.u_computer_name = scTask.getValue("u_computer_name"); //CHECK YOUR FIELD NAME AND REPLACE IF REQUIRED
	task.order = 200;
}

Please mark my respsone as helpful/correct, if it answer your question.

Thanks

thank you very much. Worked like a charm!