- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2020 02:42 AM
Hi all,
I am working currently on Inbound action. i need to close the task based on email. The email contains external RITM number and i have a field to store this external RITM number. I am comparing this external RITM number with the field on table. if the number is available then fetching the internal RITM number. now i need to close the task in this RTM and with some specified short description. the code i am using here is:
var email = new GlideRecord('sys_email');
email.addQuery('sys_id','9c6f8fdfdb1b98107c5e1bbf2996194b');
email.query();
if(email.next()){
var desc = email.body_text.indexOf("ExternalRITM: ");
var str = email.body_text.substring(desc); //To store the data after "Summary of Requested item:"
gs.print("Description is: " + desc);
gs.print("String is: " + str);
if(desc>-1)
{
var ritm = str.indexOf("RITM0"); //To search any string available which starts from "RITM" after str
gs.log("Index of RITM" + ritm);
if(ritm>-1)
{
var ticket = str.substring(ritm,ritm+13);
gs.log("Ticket number = " + ticket);
var gr = new GlideRecord("sc_req_item");
gr.addActiveQuery();
gr.addQuery('external_ritm',ticket);
gr.query();
if(gr.next()){
var int_ritm = gr.getValue('sys_id');
gs.print("Internal RITM number: " + int_ritm);
var task = new GlideRecord('sc_task');
task.addQuery('sys_id','55d58b9bdb1b98107c5e1bbf2996192a');
gs.print("Request item" + task.getValue('request_item','sys_id'));
//task.addQuery('request_item','int_ritm');
task.addEncodedQuery('short_descriptionSTARTSWITHInform user - Order is placed');
task.query();
if(task.next())
{
gs.print("task number" + task.number);
var t = task.getValue('request_item','sys_id');
gs.print("in task query T: " + t);
gs.print("in task query INT: " + int_ritm);
if(t == nt_ritm)
{
gs.Print("Got the RITM at last");
}
}
}
}
}
}
I am unable to compare the sys_ids of RITM in sc_req_item(int_item) table and sc_task table(t). any idea, how i can compare these two sys_ids. This is a background script.
Output of script
I appreciate you help. Thank in advance.
Regards,
SNeha
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2020 02:53 AM
Hi,
Did you try using logs to check till which line it is working?
this is the updated line; the variable should not be in quotes
task.addQuery('request_item',int_ritm);
Also update below line as this
var t = task.getValue('request_item');
so updated final script
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2020 03:51 AM
Hi Sneha,
Happy to help.
Please add some debug statements
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2020 04:10 AM
All issues sorted out.. Thank you all for quick response. 🙂
Have a nice day.
Regards,
Sneha Udnur