- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2021 04:26 AM
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??????????
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2021 05:40 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2021 05:40 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2021 05:05 AM
Thanks sam,
your code was so helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2021 05:40 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2021 05:06 AM
Thanks Enrique