using "contains" (LIKE) in an encoded query

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2019 01:27 PM
Hey Guys,
I'm trying to use the below query in an "if" workflow activity. The purpose is to check for the AD error that equals "Already in the group" - (HRESULT: 80071392). If I find 80071392 in the error message, then we consider it a non-issue and move on. If I don't find the error, it means my previous failure from the "add to AD group" activity needs to be looked at.
My problem (I think) is the last strQuery line. It doesn't seem to evaluate "messageLIKE0x80071392" correctly / at all. Is that the correct syntax for using "contains/like" in an encoded query?? I copied and pasted it directly from the breadcrumb on the wf_log table, but it still doesn't seem to be correct. Any help is appreciated, I've been fighting with this one all day and don't find too much out there about using LIKE in an encoded query.
var rec = new GlideRecord('wf_log');
var strQuery = 'context=current.context'; //current workflow context sys id
strQuery = strQuery + '^context.stage.value=add_user_acc_group'; //"Adding Access" stage value
strQuery = strQuery + '^level=2'; //level 2 = error
strQuery = strQuery + '^context.id.number=current.number'; //current RITM number
strQuery = strQuery + '^messageLIKE0x80071392'; //AD error code for "already in group" in message
rec.addEncodedQuery(strQuery);
rec.query();
if(rec.next()) {
return 'yes'; //we found a "user already in group" error - no action needed
} else {
return 'no'; //error code 0x80071392 wasn't present, error needs to be checked
}
}
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2019 05:37 AM
Hey harshtimes,
Thank you for the reply. I got the same result when trying the above. Even though it should find a record, it doesn't.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2019 09:16 PM
It is hard to give you the exact answer without knowing your instance, but I can recommend some steps you can take to debug any encoded query issue you might have:
How To Write GlideRecord Queries Like A Pro
Follow the approach there and you cannot fail!
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2019 05:41 AM
I noticed your message says:
Already in the group" - (HRESULT: 80071392).
And your code is prefixed with 0x8017...
Have you tried removing the 0x?
strQuery = strQuery + '^messageLIKE80071392'; //AD error code for "already in group" in message

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2019 05:51 AM
Morning Chuck,
Sorry, that was a typo on my part. The actual error I see in the logs, and that I'm trying to find with the query is:
The object already exists. (Exception from HRESULT: 0x80071392)
HRESULT: [-2147019886]
Stack Trace:
I did remove the 0x for kicks and try, and I still get the wrong output.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2019 12:13 PM
Thanks for the help. Your query got me what I needed to read the workflow log for error handling. In case others need the code here's my debug query.
USE: Scripts > Background Scripts
NOTE:
* Swap out the RITM number for an existing RITM sys_id
* This version includes Chucks suggested message query
//DEBUG--START FAUX CURRENT--
//Author: Chuck Tomasi! (https://community.servicenow.com/community?id=community_question&sys_id=3341932ddbdcdbc01dcaf3231f96196d)
var current = new GlideRecord('sc_req_item');
current.get('3488a0af1b833b0089f30d43cd4bcb0a'); //RITM sys_id
//DEBUG--END FAUX CURRENT--
function readWf_log(){
var rec = new GlideRecord('wf_log');
var strQuery = 'context.sys_id='+current.context.sys_id; //current workflow context sys id
strQuery = strQuery + '^level=0'; //level 0= info, 1= warn, 2 = error
strQuery = strQuery + '^messageLIKE80071392'; //AD error code for "already in group" in message
rec.addEncodedQuery(strQuery);
rec.query();
if(rec.next()) {
gs.debug(rec.sys_created_on + ", " + rec.level + ", " + rec.message); //DEBUG: added to print found logs
return 'yes'; //we found a "user already in group" error - no action needed
} else {
return 'no'; //error code 0x80071392 wasn't present, error needs to be checked
}
}
readWf_log();