When query returns no records return 'no'

alexcharleswort
Tera Expert

I don't quite know if this is possible to do in one script...

BUT, I am in the workflow and making an if activity. Basically what I want it to do it to query two tables (alm_asset, u_cellular_table). If both of these turn out with no matching records, return no. If one or both of them produce records then return yes.

It seems to be reading the first half just fine. If there is a record that matches on the alm_asset table, then it returns yes. If there are no assets on the alm_asset table it returns no.

It appears to always be returning no for the last half. If there is a record that shows on the alm_asset table but none on the u_cellular_table, it returns yes. If there are no matching records on the alm_asset table but there are records on the u_cellular_table that match, it still returns no.

Here is my script...

    answer = ifScript();

function ifScript(){


var gr = new GlideRecord('alm_asset');
gr.addQuery('assigned_to', current.variables.term_name);
gr.addQuery('model.certified', true);
gr.query();
if(gr.next()){
  return 'yes';

} else {


gr = new GlideRecord('u_cellular_table');
gr.addQuery('u_employee_id_2', current.variables.term_empid);
gr.addQuery('u_carrier', '!=', 'Allowance');
gr.addQuery('u_carrier', '!=', 'NoAllowance');
gr.query();
if(gr.next()){
  return 'yes';
} else {
  return 'no';
}
}
}

Any help would be greatly appreciated!

Thanks!

1 ACCEPTED SOLUTION

Kalaiarasan Pus
Giga Sage

Just changed the variable name of the second. Give it a try



answer = ifScript();  


 


function ifScript(){  


 


var gr = new GlideRecord('alm_asset');  


gr.addQuery('assigned_to', current.variables.term_name);    


gr.addQuery('model.certified', true);  


gr.query();  


if(gr.next()){  


  return 'yes';  


} else {  


 


 


var gr1 = new GlideRecord('u_cellular_table');  


gr1.addQuery('u_employee_id_2', current.variables.term_empid);    


gr1.addQuery('u_carrier', '!=', 'Allowance');  


gr1.addQuery('u_carrier', '!=', 'NoAllowance');  


gr1.query();  


if(gr1.next()){  


  return 'yes';  


} else {  


  return 'no';  


}  


}  


}


View solution in original post

2 REPLIES 2

Kalaiarasan Pus
Giga Sage

Just changed the variable name of the second. Give it a try



answer = ifScript();  


 


function ifScript(){  


 


var gr = new GlideRecord('alm_asset');  


gr.addQuery('assigned_to', current.variables.term_name);    


gr.addQuery('model.certified', true);  


gr.query();  


if(gr.next()){  


  return 'yes';  


} else {  


 


 


var gr1 = new GlideRecord('u_cellular_table');  


gr1.addQuery('u_employee_id_2', current.variables.term_empid);    


gr1.addQuery('u_carrier', '!=', 'Allowance');  


gr1.addQuery('u_carrier', '!=', 'NoAllowance');  


gr1.query();  


if(gr1.next()){  


  return 'yes';  


} else {  


  return 'no';  


}  


}  


}


Man... what a facepalm moment.


And I know I'm even doing similar things in other places. Thanks for the help, Kalai!