- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2023 12:00 PM
Hello
This is regarding a below script which is not working as expected.
Pls let me know the issue in below script , why it is not performing the AddorCondition line.
I have tried running it in BG , but outcome is "cannot convert null to an object" - on line addorCondition it is giving error.
var result;
var ritmObj = {};
ritmObj.user = [];
ritmObj.license = [];
var grAlm = new GlideRecord('xyz');
var grAlm1 = grAlm.addQuery('licensed_by.sys_id=4f9e91df971f6d507fbb77771153af46'+ '^assigned_to=' + '429e96b5dba5b0d4e65aa90b8a9619a3');
grAlm1.addOrCondition('licensed_by.sys_id=d0ad5ddb971f6d507fbb77771153af2f' + '^assigned_to=' + '429e96b5dba5b0d4e65aa90b8a9619a3');
grAlm.setLimit(1);
grAlm.query();
if (grAlm.next()) {
ritmObj.license = 'true';
} else {
ritmObj.license = 'false';
}
result = JSON.stringify(ritmObj);
gs.log('result is'+result);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2023 12:43 PM
Try this:
var result;
var ritmObj = {};
ritmObj.user = [];
ritmObj.license = [];
var grAlm = new GlideRecord('xyz');
grAlm.addEncodedQuery('licensed_by.sys_id=4f9e91df971f6d507fbb77771153af46'+ '^assigned_to=' + '429e96b5dba5b0d4e65aa90b8a9619a3^NQlicensed_by.sys_id=d0ad5ddb971f6d507fbb77771153af2f' + '^assigned_to=' + '429e96b5dba5b0d4e65aa90b8a9619a3');
grAlm.setLimit(1);
grAlm.query();
if (grAlm.next()) {
ritmObj.license = 'true';
} else {
ritmObj.license = 'false';
}
result = JSON.stringify(ritmObj);
gs.log('result is'+result);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2023 12:14 PM
Hi @Dinesh90 ,
addOrCondition accepts 2 or 3 parameters, first is the field name, second is the operator and third is the value which is an object
So, in this line:
grAlm1.addOrCondition('licensed_by.sys_id=d0ad5ddb971f6d507fbb77771153af2f' + '^assigned_to=' + '429e96b5dba5b0d4e65aa90b8a9619a3');
The javascript parser is treating the second and third parameter as null, hence you are getting that error
This looks more like an encoded query, I would suggest you to use addEncodedQuery();
You can build your query from the list view and the copy the query and add it inside the addEncodedQuery() method
Refer to this doc: https://developer.servicenow.com/blog.do?p=/post/training-encoded-query/
If my answer has helped with your question, pelase mark it as correct and helpful
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2023 12:43 PM
Try this:
var result;
var ritmObj = {};
ritmObj.user = [];
ritmObj.license = [];
var grAlm = new GlideRecord('xyz');
grAlm.addEncodedQuery('licensed_by.sys_id=4f9e91df971f6d507fbb77771153af46'+ '^assigned_to=' + '429e96b5dba5b0d4e65aa90b8a9619a3^NQlicensed_by.sys_id=d0ad5ddb971f6d507fbb77771153af2f' + '^assigned_to=' + '429e96b5dba5b0d4e65aa90b8a9619a3');
grAlm.setLimit(1);
grAlm.query();
if (grAlm.next()) {
ritmObj.license = 'true';
} else {
ritmObj.license = 'false';
}
result = JSON.stringify(ritmObj);
gs.log('result is'+result);