- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-27-2017 06:56 AM
I am having issues with recording a ticket number in the current record after an insert. I have a "Convert to Task" button on my incident form so that if an incident comes in that should have been a request, this can be used to convert the incident into a task and cancel the incident. Everything works great with the exception of "relating" the two records. I am able to pass the current incident number into the task, but unable to obtain the new ticket number to add to my closing of the incident. The code I have thus far is below, and is a UI Action. Any help would be GREATLY appreciated!
function convertToTask() {
// Generate Task
var task = new GlideRecord("sc_task");
task.initialize();
task.short_description = g_form.getValue("short_description");
task.cmdb_ci = g_form.getValue("cmdb_ci");
task.assignment_group = g_form.getValue("assignment_group");
task.assigned_to = g_form.getValue("assigned_to");
task.comments = g_form.getValue("comments");
task.priority = g_form.getValue("priority");
task.description = g_form.getValue("description");
task.state = 1;
task.u_contact = g_form.getValue("caller_id");
task.u_related_incident = g_form.getDisplayValue("sys_id"); //This is the part I am having issues with. No matter what I use, this field is blank in the new task. u_related_incident is a reference field.
var taskSysID = task.insert();
// Close Incident
g_form.checkMandatory = false;
g_form.setValue("close_code", "Cancelled");
g_form.setValue("u_related_request", taskSysID);
g_form.setValue("close_notes", "Incident has been automatically updated to a request.");
g_form.setValue("state", 7);
gsftSubmit(gel('sysverb_update_and_stay'));
// Jump over to new Task
top.location.href =
"https://tractorsupplydev.service-now.com/nav_to.do?uri=/sc_task.do%3Fsys_id%3D" + taskSysID +"%26sysparm_record_target%3Dsc_task%26sysparm_record_row%3D1%26sysparm_record_rows%3D662%26sysparm_record_list%3Dactive%253Dtrue%255EORDERBYDESCnumber";
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-27-2017 08:11 AM
Hi Kevin,
Try this,
task.u_related_incident = g_form.getUniqueValue();
Regards,
Sagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-27-2017 07:02 AM
Hi Kevin,
Is u_request a reference field, referencing sc_task? If not it wont work..
Btw are you using this script in some single place, then i am afraid to say that you have mixed server and client scripts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-27-2017 07:04 AM
BTW, if a sc_task record is created then a stray record should be avoided. place it under a req and ritm record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-27-2017 07:09 AM
The way they implemented "requests" here is that they are using straight Catalog Tasks, and are not using the req or ritm records at all. I did have u_request as a reference field and it was not posting the results, meaning that the field appeared to be blank.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-27-2017 07:14 AM
Can you please post the screenshot for better clarity