AnsweredAssumed Answered

In a Workflow, how to fill a list box with a call rest?

Question asked by lina on Oct 16, 2018

I create a workflow in servicenow for call rest outbound:

In Workflow Properties => I created 2 variables in inputs:

  • u_url_rest of type string => url of the call rest outbound
  • u_cities of type list box or list collector or reference list => list must be filled in relation to the u_url_rest

My questions :
1) How to fill a list box compared to the u_url_rest?
2) where should I put my script, and how do I call the script in my workflow?

I started writing the script but I am stuck :

var r = new sn_ws.RESTMessageV2 ('x_20000_tstrest.Cities REST', 'Get All Cities');
r.setStringParameterNoEscape ('url_server', workflow.inputs.u_url_rest);

response = r.execute ();
var responseBody = response.getBody ();
var httpStatus = response.getStatusCode ();
var results = responseBody.split (',');
var restGR = new GlideRecord ('u_cities');
restGR.initialize ();
restGR.u_city_id = results [0];
restGR.u_city_name = results [1];
restGR.insert ();