Insert data into servicenow table from a Rest call via flow designer to a 3rd party Application

Rochel hans
Tera Contributor

Hello Team,

 

@Chuck Tomasi @Ankur Bawiskar 

We want to do a "GET" call from flow designer's REST to a 3rd party tool to extract data , process and then insert the same into servicenow.

What's the best way to do this , either save the response as an attachment and do via import set's or use the "script" step on flow designer.

Kindly guide with a sample script.

Regards

Rochel Hans

 

9 REPLIES 9

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi,

There's a REST step or a Script step can be used to make the GET call. If it's a Script step, reply can be used to create a GlideRecord to insert it into ServiceNow.

Another option is to convert the date to String and use Flow to create a record.

hello Ozawa ,

Thanks for a quick response , would you be able to add sample code snippets on how to proceed.

Regards

Rochel hans

Simple sample of Action to GET user info using ServiceNow's REST API and insert into ServiceNow table. If the REST API supports paging, the REST call  can be looped. Note that ServiceNow does have a max size of response.

It may also be better to use Flow to insert the record in case low coding is desired.

(function execute(inputs, outputs) {
    var instanceName = '<instance name>';
    var user = '<user name>';
    var password = '<password>;

    var request = new sn_ws.RESTMessageV2();
    request.setEndpoint('https://' + instanceName + '.service-now.com/api/now/table/sys_user?sysparm_fields=user_name%2Cemail%2Ctitle&sysparm_limit=1');
    request.setHttpMethod('GET');

    request.setBasicAuth(user, password);
    request.setRequestHeader("Accept", "application/json");

    var response = request.execute();
	var json = JSON.parse(response.getBody());
	var results = json.result;
	for (var i=0; i<results.length; i++) {
		var grUser = new GlideRecord('sys_user');
		grUser.initialize();
		grUser.user_name = results[i].user_name + '_' + i;
		grUser.title = results[i].title;
		grUser.email = results[i].email;
		grUser.insert();
	}
})(inputs, outputs);

hello Ozawa, 

Thanks again , will try this out to . We will need to support pagination as we might expect more than 500 + records in the response. 

Will add details once tested.

Regards

Rochel Hans