- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2022 09:00 PM
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
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2022 09:08 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2022 09:08 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2022 09:12 PM
Hi Ankur,
That worked.
I should not make silly mistakes while writing scripts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2022 09:09 PM
Hi
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2022 09:13 PM
Hi Maik,
I forgot to ask above, why we are using sys_id here, why reqitm.number didn't worked ?