How to copy the Variable input from catalog item to Incident or RITM?

vishal jaiswal
Tera Contributor

Scenario: There is variable "XYZ" in a catalog item which is "Reference" type and table is "Task".

Other variable is "Requested for" which is "Reference" type and table is "sys_user".

And Last variable is "Description" which is "multiline text" type.

Expected sol 1: If the user selects 'Incident' from "XYZ" variable then the "Requested for" and "Description" input should be copied to selected Incident's work notes.

 

Expected sol 2: If the user selects 'RITM' from "XYZ" variable then the "Requested for" and "Description" input should be copied to selected RITM ticket's work notes if that RITM does not contain SCTASK. If the RITM contain SCTASK then data should be copied to that RITM's SCTASK work notes.

 

Note: Here I am using workflow for this catalog item.

Is there any way to achieve this solution??????????

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi Vishal,

I would recommend you use a Workflow Script on the catalog item that will amend the task e.g.:

Scenario 1:

var task = new GlideRecord("task");
task.get('sys_id', current.variables.task_variable);
task.work_notes = "Requested for: " + current.variables.requested_for_variable + "\n + "\n" + "Description: " + current.variables.description_variable;
task.update();

Scenario 2:

var reqitem = new GlideRecord("sc_req_item");
reqitem.addQuery('sys_id','current.variables.task_variable');
reqitem.query();

if (reqitem.next()){

reqitem.work_notes = "Requested for: " + current.variables.requested_for_variable + "\n + "\n" + "Description: " + current.variables.description_variable;
reqitem.update();

var reqtask = new GlideRecord("sc_task"):
reqtask.addQuery('request_item', reqitem.sys_id);
reqtask.query();

while (reqtask.next()){

reqtask.work_notes = "Requested for: " + current.variables.requested_for_variable + "\n + "\n" + "Description: " + current.variables.description_variable;
reqtask.update();

 

}

}

You can add criteria in your catalog items to restrict task types so that each workflow runs the correct script or create an if statement on your workflow to direct the workflow depending on class type of selected task.

Let me know if this helps and mark this as helpful/solved.

Thanks,

Enrique
 

View solution in original post

5 REPLIES 5

Sam Ogden
Tera Guru

Hi Vishal,

In your workflow you could have a run script activity that checks the variable XYZ.  I'm guessing that the user selects a task number in that variable so it would be something like:

var requestFor = current.variables.request_for;
var desc = current.variables.description;
var taskID = current.variables.xyz; // replace xyz with your actual variable name

var task = new GlideRecord('task');
task.addQuery('sys_id', taskID);
task.query();
if(task.next()){
if(task.task_type == 'sc_req_item'){
	var scTask = new GlideRecord('sc_task');
	scTask.addQuery('request_item', taskID);
	scTask.query();
	if(scTask.next()){
		scTask.description = requestFor + ' - ' + desc;
		scTask.update();
} else {

task.description = requestFor + ' - ' + desc;
task.update();
}
}

Not tested the code so this will need to be tested.

Hope this helps

Thanks

Sam

Thanks sam,

your code was so helpful.

Community Alums
Not applicable

Hi Vishal,

I would recommend you use a Workflow Script on the catalog item that will amend the task e.g.:

Scenario 1:

var task = new GlideRecord("task");
task.get('sys_id', current.variables.task_variable);
task.work_notes = "Requested for: " + current.variables.requested_for_variable + "\n + "\n" + "Description: " + current.variables.description_variable;
task.update();

Scenario 2:

var reqitem = new GlideRecord("sc_req_item");
reqitem.addQuery('sys_id','current.variables.task_variable');
reqitem.query();

if (reqitem.next()){

reqitem.work_notes = "Requested for: " + current.variables.requested_for_variable + "\n + "\n" + "Description: " + current.variables.description_variable;
reqitem.update();

var reqtask = new GlideRecord("sc_task"):
reqtask.addQuery('request_item', reqitem.sys_id);
reqtask.query();

while (reqtask.next()){

reqtask.work_notes = "Requested for: " + current.variables.requested_for_variable + "\n + "\n" + "Description: " + current.variables.description_variable;
reqtask.update();

 

}

}

You can add criteria in your catalog items to restrict task types so that each workflow runs the correct script or create an if statement on your workflow to direct the workflow depending on class type of selected task.

Let me know if this helps and mark this as helpful/solved.

Thanks,

Enrique
 

Thanks Enrique