Data Loader in Data Source

sieusaopolo15
Tera Guru

Hi,
I'm using this data loader in Data Source, I wonder if data retrieve from API has status code != 200 like in my code. How can I make whole import set state as 'Completed with errors' instead of 'Cancelled'.

sieusaopolo15_0-1704423753211.png

 

var response = restMessage.execute();
var statusCode = response.getStatusCode();
if (statusCode == 200) {
	var body = JSON.parse(response.getBody());
	body.forEach(function(e) {
		import_set_table.insert(e);	
	});
} else {
	gs.log("Status Code: " + statusCode);
}

 

1 ACCEPTED SOLUTION

Hi @sieusaopolo15 

okay, now I got your point.

You could an onStart script to check the connection and abort if required before it comes to the transformation.

See https://developer.servicenow.com/dev.do#!/learn/courses/utah/app_store_learnv2_importingdata_utah_im... 

Maik

View solution in original post

3 REPLIES 3

Maik Skoddow
Tera Patron
Tera Patron

Hi @sieusaopolo15 

it seems you never have retrieved any data, right? If so make first sure you can retrieve any data and then start the import again.

Maik

Hi @Maik Skoddow, The API returns JSON data like I expected but I need to add exception like when data information send to server is incorrect or server is down for maintenance then my instance would receive status code like 500 or 400 from the server. I wonder if I can stop the current import set in the 'else' clause and set the state of that transform histories (sys_import_set_run) as "Complete as errors" in the my if else condition.

Hi @sieusaopolo15 

okay, now I got your point.

You could an onStart script to check the connection and abort if required before it comes to the transformation.

See https://developer.servicenow.com/dev.do#!/learn/courses/utah/app_store_learnv2_importingdata_utah_im... 

Maik