The CreatorCon Call for Content is officially open! Get started here.

How to pass an optional column in relative path of scripted rest api

Divya95
Tera Contributor

Hi ,

We need to perform a GET operation , by query columns Incident ID ,Status ,Assigned Group .

But Assigned Group is optional .How do i specify this in relative path or do I need  to specify this condition in the code .

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Divya,

Have your relative path as follows and check in code whether value is present in url parameter or not.

Relative path: /apiName/{incidentId}/{status}/{assignmentGroup}

Script:

var incidentId = request.pathParams.incidentId;

var status = request.pathParams.status;

var assignmentGroup = request.pathParams.assignmentGroup;

Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur ,

 

But if i dont provide assignment group value ,it throws error

 

"Requested URI does not represent any resource:

So how do i get a valid reponse even if assignment group is not provided .

Hi Divya,

Base UI parameter cannot be optional; only query string parameters can be optional

I would suggest to have following approach.

Inform 3rd party to send the values with separated with some special character and in your script you split and use

example:

singleValue could be INC001@In Progress@Group1

Relative path: /apiName/{singleValue}

Script:

var singleValue = request.pathParams.singleValue;

var split1 = singleValue.split("@");

var incidentId = split1[0];

var status = split1[1];

var assignmentGroup = split1[2];

I will still check and let you know if better way found.

Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader