pulling a REST data pull into a transform table

Jack62
Giga Guru

Evening guys

 

I have been working on a rest data pull which now I have the right credentials is working when doing a test on the rest message itself. I would like to pull this data into a transform table so I can then map into the relevant CMDB tables. Could someone provide guidance on how to do this. I assume it will be via a script include kicked off using a scheduled job. right now, It just needs to be a simple dump of the data into my new transform table.

 

Thanks as always

 

JAck

4 REPLIES 4

Harish KM
Kilo Patron
Kilo Patron

Hi @Jack62 refer this below thread, once you receive the response parse them and insert it into your custom table and map the import set sysid to a field detailed steps below .

https://www.servicenow.com/community/now-platform-forum/wanting-to-import-data-using-external-rest-s...

Regards
Harish

Sateesh Kumar D
ServiceNow Employee
ServiceNow Employee

Hello,

 

You can create a flow, with trigger as "Scheduled" and add an action to the flow which you should have created first with a step "Rest" and couple more step to parse results, refer below link for more detail

 

https://www.servicenow.com/community/hrsd-blog/rest-integration-using-flow-designer-integration-hub-...

Jack62
Giga Guru

thankyou for the suggestions guys I will take a look at both. Below is my script include I was expecting to kick of the rest message and then dump the data into our staging table. Any thoughts on what is wrong currently?

 

var PullSolarWindsCIdata = Class.create();
PullSolarWindsCIdata.prototype = {
    initialize: function() {
    },

    solarwindsImport : function() {

try {


   //Send REST get to grab XML blob


   var r = new sn_ws.RESTMessageV2('solar winds PoC', 'Solar Winds Pull');


  // r.setStringParameter('key', 'Private');


   var response = r.execute();


   var responseBody = response.getBody();


   var httpStatus = response.getStatusCode();


   var parsed = new XMLHelper().toObject(responseBody);


   for (var n in parsed.Location[0]){


   //gs.log("Parsed.Location[0][" + n +"]= " + parsed.Location[0][n]); //use this to see your XML objects


}


}catch(ex) {


   var message = ex.getMessage();


}


//Create a new import set


var crImpSet = new GlideRecord('sys_import_set');


crImpSet.initialize();


crImpSet.mode = 'synchronous';


crImpSet.table_name = 'u_location_api_import'; //Set the extended importset table


crImpSet.state = 'loading';


crImpSet.insert();


var locs = parsed.Location;


var restGR = new GlideRecord('u_solar_winds_transform_table'); //Query extended import set rows table


//Loop through the xml chunks until 0 remain creating import set rows to be transformed


for (var i = 0; i < locs.length; i++) {


   restGR.initialize();


   restGR.u_id = locs[i].ID;


   restGR.u_name = locs[i].Name;


   restGR.u_typedescription = locs[i].TypeDescription;


   //gs.log("Tots " + locs[i].TypeDescription);


   restGR.u_latitude = locs[i].Address.Latitude;


   restGR.u_subdivision = locs[i].Address.Subdivision;


   restGR.u_typecode = locs[i].TypeCode;


   restGR.u_countryname = locs[i].Address.CountryName;


   restGR.u_addressline1 = locs[i].Address.AddressLine1;


   restGR.u_postalcode = locs[i].Address.PostalCode;


   restGR.u_formattedaddress = locs[i].Address.FormattedAddress;


   restGR.u_city = locs[i].Address.City;


   restGR.u_longitude = locs[i].Address.Longitude;


   restGR.u_phonenumber = locs[i].TelephoneNumber.PhoneNumber;


   restGR.u_county = locs[i].Address.County;


   restGR.u_timezonecode = locs[i].TimeZone.TimeZoneCode;


   restGR.u_address = locs[i].Address.FormattedAddress;


   restGR.sys_import_set = crImpSet.sys_id; //This is the sys_id from import set above


   restGR.insert();


}}};

Jack62
Giga Guru

Any thoughts on why the above script is not working from anyone? A pointer in the right direction would be most helpful.