Rest Connector JS Prescript
Last updated
Last updated
Sometimes simply doing a REST call and saving a parameter is not enough to get you the results you are looking for. The data between calls need some manipulation... this is where our JS prescript function can come into play.
Run a JS script on available data, which may come from saved parameter fields or a pre-request, then save data as a parameter to be used in your next request call. This can be extremely useful when dealing with tricky paging rules or sorting functions etc.
Check out the update in the Rest Connector Definition (this is also available as a publisher):
"Sometimes you may need to apply a calculation or two on some parameters or even a pre-request in order to get the data you are looking for. In this case you can use our "PreRequestScript" node. This can be used in both PreRequests and Request function and will run prior to the actual request. Currently we only allow javascript notation in the Code node. Note: if you want to save a parameter for future calls, you need to add the node in the parameter section (Path is not required if it is not being referenced out the document). To reference it in you JS script simply use this.yourParameterName and to save it just return it at the end of the call with the correct yourParameterName."
If you would like to run through a test example the syntax is shown in the Rest Connector Definition page, or take a look at the "Follow Along Example".
Don't forget to Restart your microservices deployment to pull the updated image. The version is available at the microservices swagger end point. 0.12.1602