How do I script a gliderecord that to query specific fields, (i.e short description, description)

ASHLE CRAIG
Giga Contributor

I am creating a Scripted REST API for the change request. I want to pull from a json file and query fields to create a change request 

1 ACCEPTED SOLUTION

Hello @ASHLE CRAIG ,

usually the syntax of glide record is like below 

var myObj = new GlideRecord('table_name'); 
// 2. Build query
 myObj.addQuery('field_name','operator','value'); 
myObj.addQuery('field_name','operator','value'); 
// 3. Execute query  
myObj.query(); 
 while(myObj.next())

{   
//Logic you want to execute.   
//Use myObj.field_name to reference record fields 
}

So in your case it would be like this 

It depends on the type of field also if its a reference we need to query with sys_id as reference accepts only sys_ids , if its string type  you can query with string ....as in your script services and assignment group are references you need to use sys_ids to compare

Also make sure you are using correct back end names of fields. (services ,short_description)etc;

(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {

    // implement resource here
    var requestBody = request.body.data;
    var change = new GlideRecord('change_request');
    
    change.addQuery('services','your services sys_id');
    change.addQuery('short_description','your short description');
    change.addQuery('description','your description value');
    change.addQuery('assignment_group','your assignement group sys_id');
   change,query();
if(change.next())
{
//execute your logic
}
    
    
    
    

})(request, response);

please mark my answer correct if it helps you

View solution in original post

8 REPLIES 8

@ASHLE CRAIG see the above response you will get an idea how to do it 

Thank you!

I noticed after I posted. 

@ASHLE CRAIG sure No problem!

if you feel this helped you please mark my answer correct and close the thread so that it will be benficial for users with same query and will be removed from unsolved list

@ASHLE CRAIG sure No problem!

if you feel this helped you please mark my answer correct and close the thread so that it will be benficial for users with same query and will be removed from unsolved list