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

Hi Maik,

 

But object.number is the correct way to access any field in the form right. Why this an exception here in sc_req_item table.

Hi

please make yourself familiar with the concept of Sys IDs: 

"number" is just a field with a kind of counter. And such field is unique identifier and also not available for all tables.

Kind regards
Maik