Checking User name in Computer table

Shreya Sinha1
Tera Contributor

Hi All,

 

I have a requirement to check whether user is there in Computer table on not.I'm writing If/else condition in workflow.Else part is not working.Could you please help me on this. 

Script-

var l=current.variables.requested_for;
var gr=new GlideRecord('cmdb_ci_computer');
gr.addQuery('assigned_to',l);
gr.query();

answer = ifScript();
//
function ifScript() {
if (gr.assigned_to!='') {
return 'yes';
}
return 'no';
}

 

ShreyaSinha1_0-1694089447129.png

 

Regards,

Shreya Sinha

1 件の受理された解決策

Brad Bowman
Kilo Patron
Kilo Patron

You're missing the gr.next() part of the GlideRecord, and all you really need to do is know if a record is returned by the GR or not, so here's one way to do that.  It's also best to put all of your code inside the function:

answer = ifScript();
function ifScript() {
    var gr=new GlideRecord('cmdb_ci_computer');
    gr.addQuery('assigned_to', current.variables.requested_for);
    gr.query();
    if (gr.next()) {
        return 'yes'; //a record was found
    }
    return 'no'; //a record was not found 
}

 

元の投稿で解決策を見る

1件の返信1

Brad Bowman
Kilo Patron
Kilo Patron

You're missing the gr.next() part of the GlideRecord, and all you really need to do is know if a record is returned by the GR or not, so here's one way to do that.  It's also best to put all of your code inside the function:

answer = ifScript();
function ifScript() {
    var gr=new GlideRecord('cmdb_ci_computer');
    gr.addQuery('assigned_to', current.variables.requested_for);
    gr.query();
    if (gr.next()) {
        return 'yes'; //a record was found
    }
    return 'no'; //a record was not found 
}