Invalid GlideRecord Query

Bishal Sharma1
Tera Contributor

Hi Experts,

 

I dont know what is being refer here. Please see below code and help me to understand why logs are showing such error ?

 

(function executeRule(current, previous /*null when async*/ ) {

    var reqitm = new GlideRecord('sc_req_item');
    reqitm.addQuery('reqitm.number', current.document_id);
	gs.log('After addquery');
    reqitm.addQuery();
    while (reqitm.next()) {
		gs.log('Inside while');
        reqitm.watch_list = current.u_reviewer;
        reqitm.watch_list.update();
    }

})(current, previous);

 

Log Statement: Invalid query detected, please check logs for details [Unknown field undefined in table sc_req_item]

Note: Business rule is written on sysapproval_approver table.

Any help would be appreciated.

 

Thanks

Bishal

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

some changes

1) you used wrong field in query

2) you should use query() and not addQuery() if you wish to query

3) while updating

(function executeRule(current, previous /*null when async*/ ) {

    var reqitm = new GlideRecord('sc_req_item');
    reqitm.addQuery('sys_id', current.document_id);

    reqitm.query();
    if (reqitm.next()) {
        reqitm.watch_list = current.u_reviewer.toString();
        reqitm.update();
    }

})(current, previous);

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

some changes

1) you used wrong field in query

2) you should use query() and not addQuery() if you wish to query

3) while updating

(function executeRule(current, previous /*null when async*/ ) {

    var reqitm = new GlideRecord('sc_req_item');
    reqitm.addQuery('sys_id', current.document_id);

    reqitm.query();
    if (reqitm.next()) {
        reqitm.watch_list = current.u_reviewer.toString();
        reqitm.update();
    }

})(current, previous);

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

 

That worked.

 

I should not make silly mistakes while writing scripts.

Maik Skoddow
Tera Patron
Tera Patron

Hi @Bishal Sharma 

please replace

 reqitm.addQuery('reqitm.number', current.document_id);

with:

reqitm.addQuery('sys_id', current.document_id);

 

Reason:

reqitm.number is not a valid column name for sc_req_item table.

 

Kind regards
Maik

Hi Maik,

 

I forgot to ask above, why we are using sys_id here, why reqitm.number didn't worked ?