How to pass an optional column in relative path of scripted rest api
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2018 10:07 PM
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 .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2018 12:08 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2018 12:37 AM
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 .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2018 01:34 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader