Help in Scripting if(gr.next()) is not working

priya149
Mega Contributor

After madrid upgrade this script is not working in prod, the same is working in kingston.

Below code is displaying description of incident on approval request in portal but description is not getting visible after madrid upgrade only for incident.

kindly guide if anything wrong in it.

if (record.source_table == 'incident') {
gs.log("Madrid Changes hello");
var inc = new GlideRecord('incident');
inc.addQuery('sys_id', record.sysapproval.sys_id.toString());
gs.log("Madrid Changes variable" + record.sysapproval.sys_id.toString());
inc.query();

if (inc.next())

{

gs.log("Madrid changes dsc" + inc.description.toString());
ticket.description = inc.description.toString();
ticket.comment_approval = 'true';

}

}

Logs are not coming inside if (inc.next()) and if I remove the IF condition value is not coming in  inc.description.toString();

In sort inc.description.toString(); is not working as well.

25 REPLIES 25

Sanjay Bagri1
Tera Guru

Hi,

Please do some changes in script:

if (record.source_table == 'incident') {  //What is the record. or please remove this line
gs.log("Madrid Changes hello");
var inc = new GlideRecord('incident');
inc.addQuery('sys_id', record.sysapproval.sys_id.toString());
gs.log("Madrid Changes variable" + record.sysapproval.sys_id.toString());
inc.query();

if (inc.next())

{

gs.log("Madrid changes dsc" + inc.description.toString());
ticket.description = inc.description.toString();
ticket.comment_approval = 'true';

}

}

all are correct .

Thanks

Sanjay

Dxsherpa.com

 

In record we are taking - var record = new GlideRecord(table_name);

as its a script include and we have many tables to query to display records on portal.

if (record.source_table == 'incident') logs are coming inside this no issue with this line.

 

Hi Priya,

But where you have create the record object in this script. please create the record object and after that try.

 

Or Please can you go through once below link might be it is also doing same.

https://community.servicenow.com/community?id=community_question&sys_id=40650baddbd8dbc01dcaf3231f96...

 

If not please let me know you query.

 

Thanks

Sanjay Bagri

 

 

asifnoor
Kilo Patron

Hi Priya,

What is the output of this line?

gs.log("Madrid Changes variable" + record.sysapproval.sys_id.toString());

And why are you comparing incident sys_id with the sysapproval sys_id? I assume both will be the difference and hence the code is not entering  inside if(inc.next())

Please check and correct that.

Mark the comment as a correct answer and also helpful once worked.