- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2017 11:06 AM
Hi All,
I'm unable to glide past the While(gr.next())
I'm unable to get into the If() condition. Any help is much appreciated. Thanks
My code:
(function executeRule(current, previous /*null when async*/) {
gs.log('R1');
// Add your code here
var gr = new GlideRecord('problem');
var cnew = current.u_problem_id.getRefRecord();
gr.addQuery('sys_id',cpNew);
cnew.getValue('number');
gr.addQuery('number',cnew.getValue('number'));
gs.log(cnew.getValue('number') + '1.2');
gr.query();
gs.log('R2');
while(gr.next())
{
if(gr.problem_state == 7)
{
current.state = 3;
current.update();
}
else
{
current.state = 15;
current.update();
}
}
gs.log('Relationship 6');
})(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2017 11:12 AM
Hey Venkat ,
You have a code error in line it should be as below :
var gr = new GlideRecord('problem');
gr.addQuery('sys_id',current.u_problem_id);
gr.query();
if(gr.next())
{
if(gr.problem_state == 7)
{
current.state = 3;
current.update();
}
else
{
current.state = 15;
current.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2017 11:12 AM
Hey Venkat ,
You have a code error in line it should be as below :
var gr = new GlideRecord('problem');
gr.addQuery('sys_id',current.u_problem_id);
gr.query();
if(gr.next())
{
if(gr.problem_state == 7)
{
current.state = 3;
current.update();
}
else
{
current.state = 15;
current.update();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2017 11:16 AM
Check your line 7 - the "cpNew" variable doesn't appear to have been declared anywhere.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2017 11:29 AM
Hi Venkat,
From the code it looks like this BR should do something like: if the associated problem state is 7 set the current state to 3, else set it to 15. Assuming that u_problem_id is a reference field, you can do it a little simpler.
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
if (current.u_problem_id.problem_state == 7) {
current.state = 3;
} else {
current.state = 15;
}
})(current, previous);
Also assuming this is running in a business rule you should make it a before business rule and get rid of the current.update(). I would also make sure that you're using some sort of changes() condition so it doesn't run on every db update.