I want to add the below two sys_id in the property and call the property inside the encoded query

Pooja Khatri
Tera Contributor

Hi All , 

 

I have a requirement where in my below script , I am passing two sys_id's in the encoded query .. 

I want to store that sys_id in the property and call that property inside the encoded query in the similar manner.

 

How can I implement this with the below query : 

 

 var grUser = new GlideRecord('sys_user_group');
    grUser.addEncodedQuery("typeLIKEfe0c590fc9d3f0003c0953598e8a66eb^ORtypeLIKE0248ea58c92ff0003c0953598e8a6616^sys_id=" + current.u_lob.toString());
    grUser.query();
    if (!grUser.next()) {
        gs.addErrorMessage(']LOB should always be of type lob or lob_internal');
        current.setAbortAction('true');
    }
11 REPLIES 11

Hi @Abhishek_Thakur - I am have written the below code , can you validate it once

 

   var grUser = new GlideRecord('sys_user_group');
    var grProperty = gs.getProperty('sys_id.type');
    grUser.addEncodedQuery("grProperty^sys_id=" + current.u_lob.toString());
    grUser.query();
    if (!grUser.next()) {
        gs.addErrorMessage('LOB should always be of type lob or lob_internal');
        current.setAbortAction('true');
    }
 

Hello @Pooja Khatri ,

 

You need to use gr.addEncodedQuery(Property nam +current.u_lob.toString()).

Hi @Abhishek_Thakur - but as per the encoded query earlier : 

 

grUser.addEncodedQuery("typeLIKEfe0c590fc9d3f0003c0953598e8a66eb^ORtypeLIKE0248ea58c92ff0003c0953598e8a6616^sys_id=" + current.u_lob.toString());

 

I am not calling the sys_id in the property , the property looks as below :

 

typeLIKEfe0c590fc9d3f0003c0953598e8a66eb^ORtypeLIKE0248ea58c92ff0003c0953598e8a6616

 

so to pass that sys_id I have called the encoded query in the below pattern : 

 

 grUser.addEncodedQuery("grProperty^sys_id=" + current.u_lob.toString());

 

how and where to store that sys_id value ?

 

 

Hello @Pooja Khatri ,

 

You have already added that value in property. So, you don't need to add the sys_id again. Just use my script.

Jaap
Tera Expert

Hi @Pooja Khatri ,
I guess instead of property you mean variable right?

You could define the sys_ids into variables and concatenate the variables into the encoded query:

// Define variables to store the sys_id values
var sysId1 = "fe0c590fc9d3f0003c0953598e8a66eb";
var sysId2 = "0248ea58c92ff0003c0953598e8a6616";

// Construct the encoded query using the variables
var encodedQuery = "typeLIKE" + sysId1 + "^ORtypeLIKE" + sysId2 + "^sys_id=" + current.u_lob.toString();

var grUser = new GlideRecord('sys_user_group');
grUser.addEncodedQuery(encodedQuery);
grUser.query();

if (!grUser.next()) {
    gs.addErrorMessage('LOB should always be of type lob or lob_internal');
    current.setAbortAction('true');
}
Was my comment helpful? Please mark as such! 🙂