Can we query substring value with a field value in GlideRecord

amanimogili
Kilo Contributor

Hi All,

We had a requirement on Email to ticket Integration. Here, we have to assign the ticket to a assignment group based on the substring in the email subject.

Ex: LCI1 Job NTM6839W (JOB09692), has failed @ 06:08:10 19 Mar 2018

Here, "NTM" is considered as mnemonic and based on that we have to assign the ticket to a assignment group.

We have created a custom table with mnemonics and assignment groups and GlideRecord this table in Inbound email action which is not working.

Below is the how we are querying the table:

 

current.caller_id = gs.getUserID();
current.u_impacted_id = gs.getUserID();
var str = email.subject.substring(8, 12).toString();
var gr = new GlideRecord('u_tws_integration');
gr.addQuery('u_mnemonics','str');
gr.query();
if(gr.next())
{
gs.log(str,'tws');
gs.log(gr.u_group,'tws');
current.assignment_group = gr.u_group;
}
else
{
current.assignment_group = 'c18c447ddb4d2e0006a6f9b9af961920';
}

 

Can someone help me on the above issue.

 

Thanks in Advance!

1 ACCEPTED SOLUTION

Mihir Mohanta
Kilo Sage

Change 

var str = email.subject.substring(8, 12).toString();

line to

var str = email.subject.substring(9, 12).toString();

 

and check.

View solution in original post

7 REPLIES 7

rammohanraomadd
Kilo Guru

HI,

 

Issue with the line no 5 in your script:

 

gr.addQuery('u_mnemonics','str'); Please replace the code with below

 

gr.addQuery('u_mnemonics',str);//Str is a variable and hence it should not be in quotes.

 

Regards,

Ram M

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,

 

See below code:

 

current.caller_id = gs.getUserID();
current.u_impacted_id = gs.getUserID();
var str = email.subject.substring(8, 12).toString();
var gr = new GlideRecord('u_tws_integration');
gr.addQuery('u_mnemonics',str);
gr.query();
if(gr.next())
{
gs.log(str,'tws');
gs.log(gr.u_group,'tws');
current.assignment_group = gr.u_group;
}
else
{
current.assignment_group = 'c18c447ddb4d2e0006a6f9b9af961920';
}


Thanks,
Ashutosh Munot

amanimogili
Kilo Contributor

I tried with the above script but still it is not working.

Mihir Mohanta
Kilo Sage

Line 5 of your script should be gr.addQuery('u_mnemonics',str);

And

You have to use current.insert() or current.update() method based on your requirement.

Please go through the below link for reference.

https://docs.servicenow.com/bundle/jakarta-servicenow-platform/page/administer/notification/referenc...

 

Thanks,

Mihir