How to I add a query parameter of Assignment Group to Scripted REST API

Dead Blade
Kilo Guru

Hello All, I have a scripted API  with query parameter searches for record count and date range of Incident records.  I would like to add a query parameter for "Assignment Group" to the script.  I have included the assigngroup in the "Query Parameter Associations"

var assigngroup   = "",

if(request.queryParams.assigngroup != "" && request.queryParams.assigngroup != null) {
        assigngroup = new GlideRecord(request.queryParams.assigngroup);
        gr.addQuery( 'inc_assignment_group.getDisplayValue()', '==', assigngroup );
    }

find_real_file.png

If a group is entered "GROUP A"

The API returns records for all groups, does not filter by the assigngroup.  If I remove ".getDisplayValue":

Response Body
{
  "results": []
}


How can I get the assigngroup to filter the results?

 

 

 

4 REPLIES 4

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,


Script is not proper:

   gr.addQuery( 'inc_assignment_group.getDisplayValue()', '==', assigngroup ); : This will not work as you have inc_assignment_group.getDisplayValue in this.

 

Use below one:

   gr.addQuery( 'inc_assignment_group.name', '==', assigngroup.toString());

 

Thanks,
Ashutosh

Thank you Ashutosh for the Script not proper.  I didn't think it would work.

Your script did not return results:

find_real_file.png

Response Body
{
  "results": []
}

DScroggins
Kilo Sage

Hello,

 

If your query parameter is assigngroup then you can reference it as such in your query (Also few changes made to your query as it was not correct):

var assigngroup = request.queryParams.assigngroup,

if(assigngroup != "" && assigngroup != null) {
        var gr = new GlideRecord('incident');
        gr.addQuery( 'assignment_group.name', assigngroup );
        gr.query();
        while(gr.next()){
           ///DO something with returned Incidents matching assignment group

        }
    }


 

Hope this helps.

 

--David

Thank you for the reply David.  Your script did not work.  The results are all Incident regardless of Assignment group when the Assigned Group is add to the Query Parameters:

find_real_file.png

 

 

Here is additional information on my script"

var assigngroup = "",

     table          = 'api_view',

     gr              = new GlideRecord(table);