- 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:17 AM
Hi Kevin,
Disable the client option and use the below logic in the second part of your code
current.u_request = taskSysID; // I believe u_request is a reference field referring to sc_task table.
var mySysID = current.update();
Regards,
Sagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-27-2017 07:22 AM
Hi Kevin,
Also use the below logic to redirect to the task record.
action.setRedirectURL(task);
action.setReturnURL(current);
Regards,
Sagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-27-2017 07:26 AM
Just realized that I posted this incorrectly. The part I am having is passing the incident number to the request. I've updated the script in the original message.
task.u_parent_incident = g_form.getDisplayValue("number");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-27-2017 07:31 AM
do you mean current.getDisplayValue()?? Screenshot would help to explain better i think..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-27-2017 07:54 AM