The CreatorCon Call for Content is officially open! Get started here.

How to compare SYS id

Sneha Agase
Kilo Contributor

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

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

11 REPLIES 11

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Sneha Agase
Kilo Contributor

Yes, the code is working till before last If

if(t == int_ritm)
{
gs.Print("Got the RITM at last");
}

this block is not executing, where t and int_ritm values are same as shown in attachment, last two lines

 

 

Hello Sneha

Convert to String before comparison and it shall work.

How can i do? any idea. i tried with toString() as well.