Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to compare SYS id

Sneha Agase
Giga 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

Hi Sneha,

Did you print both the sys_ids?

Did you compare if they are same

Regards
Ankur

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

Hi Sneha,

What is the output of these 2 lines? are they same or different?

gs.print("in task query T: " + t);
gs.print("in task query INT: " + int_ritm);

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

Sneha Agase
Giga Contributor

the RITM no in sc_task is returning null. even if i remove quotes, the comparison ia failing.

Hi Sneha,

did you change line as this

var t = task.getValue('request_item');

gs.print("in task query T: " + t);
gs.print("in task query INT: " + int_ritm);

if(t.toString() == nt_ritm.toString()){

}

Regards
Ankur

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

Sneha Agase
Giga Contributor

Thank you all, the issue has solved. I was comparing number with sys_id. The issue is now solved but the inbound action is not updating the task now. It is skipping with comments- "did not create or update sc_task using current". Any idea about this.