- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2022 01:30 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2022 02:18 PM
Hello
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2022 02:22 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2022 02:23 PM
Thank you!
I noticed after I posted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2022 02:24 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2022 02:29 PM
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