using "contains" (LIKE) in an encoded query

Jason Stephens
Kilo Guru

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

}
}

 

9 REPLIES 9

Matthew Glenn
Kilo Sage

You can use LIKE in an encoded query and your syntax is fine for the "messageLIKE" condition.

However, the id field on the context record is a Document type. I may be wrong, but I don't think you can dot-walk with Document fields in a Glide Record query like that. 

If you hard code a few values into your snippet above and run it in a background script, what do you get? 

Hi Matthew,

 

Thanks for the reply.  If I run it in background scripts, it seems to work like it should (below is what I ran).  If I change the messageLIKE line, it will return yes or no, based on that change.  I've also logged my values as I run the workflow, and they are all valid outside of the query.

 

var rec = new GlideRecord('wf_log');
var strQuery = 'context=da19d09e1b63e300735ea7d4bd4bcb7c';                                              //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=RITM0010247';            //current RITM number 
strQuery = strQuery + '^messageLIKE0x80071392';                    //AD error code for "already in group" in message

rec.addEncodedQuery(strQuery);
rec.query();

if(rec.next()) {
gs.print("Yes");  
//return 'yes';        //we found a "user already in group" error - no action needed
} else {
gs.print("no");
//return 'no';         //error code 0x80071392 wasn't present, error needs to be checked

}

HarshTimes
Tera Guru

All looks good except id in below line. In out of box instance i am not able to find this field name "id".

'^context.id.number=current.number';

 

 

-Harsh

Update to '^context.id.number=current.sys_id'; // it should be the sysid of the task record not the number