Configuring System Web Services

Mark94
Kilo Expert

Hi,

Help. I'm stuck!

I'm trying to import device information from Vodaphone's airwatch service into ServiceNow.

I've created an Outbound Rest message as per the info I've found here - https://community.servicenow.com/community?id=community_article&sys_id=cd3ce661dbd0dbc01dcaf3231f96191f

That bit works when I perform a test. It displays the information I want. What I can't figure out is how I move forward from the test to actually getting the data into a table.

I've tried creating an inbound web service, but that doesn't seem to give me the option to make it do anything. The docs say I need to create a transform file, but I've pulled no data into ServiceNow to transform. Now I'm rather lost. Do I need a scripted web service? Any pointers gratefully received.

Thank you!

1 ACCEPTED SOLUTION

Mark94
Kilo Expert

Hi, I'm getting somewhere.

I had set coalesce on the serial number field, so as a temporary measure removed that.

I've found the problem. So simple. A case of it being case sensitive!

I had this in my script...

gr.u_Udid = parsed.Devices[i].Udid;
                   gr.u_SerialNumber = parsed.Devices[i].SerialNumber;
                   gr.u_MacAddress = parsed.Devices[i].MacAddress;
                   gr.u_Imei = parsed.Devices[i].Imei;
                   gr.u_EasId = parsed.Devices[i].EasId;
                   gr.u_AssetNumber = parsed.Devices[i].AssetNumber;
                   gr.u_DeviceFriendlyName = parsed.Devices[i].DeviceFriendlyName;
   gr.insert();

 

..but each of the gr_u_xxx variables should all be lower case! D'oh. Changed that and data is now flowing in.

Phew. Feel like I'm back on track.

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Mark,

So you have the Vodafone endpoint which would give you few details. once you get those details you can parse the response and populate it in some custom table.

What is the confusion here?

Why inbound web service or scripted web service is requrired?

Will Vodafone team be consuming ServiceNow's endpoint? if yes then it makes sense to create an API in ServiceNow

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Mark94
Kilo Expert

Hi Ankur,

Having following the instructions to build an Outbound Rest Message, I click test, and that confirms the connection is ok, but it's not actually importing the data anywhere.

So my confusion is... how do I get it to populate some custom table - How do I get the data into a table in ServiceNow.

Why inbound web service or scripted web service...? yep. That's my question... Do I need one of those services to get the data into a table?

Will Vodafone team be consuming ServiceNow's endpoint..? Vodafone have all the hardware information about the mobile devices that we own. We just want that information visible in ServiceNow. We don't want to send anything back to Vodafone.

Kind Regards,

Mark.

Mark94
Kilo Expert

Hi,

I'm still fumbling in the dark with this. This is where I've got to so far...

 

  1. I created an Outbound REST Message called “AirWatch”, and a REST message name called “Get” (Test runs are successful)

  2. I created a new database called, “Mobile Device [u_mobile_device]”, that extends “Hardware [cmdb_ci_hardware]”. I added in a number of the field names that were returned in the test response in step one.

  3. I then created a staging table called, “Airwatch Import Table [u_airwatch_import_table]”, that extends “'sys_import_set_row” - This makes it accessible by the Transform Map. I added in the same fields from step 2.

  4. I then created a transform map called “AirWatch”. Selecting the newly created tables, I then paired the fields.

  5. I created a scheduled job called “AirWatch Import” that runs the following script.

 

----------------------------------------------

try {
   var r = new sn_ws.RESTMessageV2('AirWatch', 'Get');
   var response = r.execute();
   if(response.getStatusCode() == '200'){
   var jsonString = response.getBody();
   var parser = new JSONParser();
   var parsed = parser.parse(jsonString);
   for(i = 0; i < parsed.Devices.length; i++){
   var gr = new GlideRecord('u_airwatch_import_table');
   gr.initialize();
   //create models
   var mm = MakeAndModelJS.fromNames(parsed.Devices[i].Platform, parsed.Devices[i].Model, "Mobile Device");
   if(mm){
                   gr.u_model = mm.getModelNameSysID();
                 }
                   gr.u_Udid = parsed.Devices[i].Udid;
                   gr.u_SerialNumber = parsed.Devices[i].SerialNumber;
                   gr.u_MacAddress = parsed.Devices[i].MacAddress;
                   gr.u_Imei = parsed.Devices[i].Imei;
                   gr.u_EasId = parsed.Devices[i].EasId;
                   gr.u_AssetNumber = parsed.Devices[i].AssetNumber;
                   gr.u_DeviceFriendlyName = parsed.Devices[i].DeviceFriendlyName;
   gr.insert();
   }
   }
   else{
   gs.logError("AirWatch import failed with a status code of " + response.getStatusCode());
   }
}
catch(ex) {
   var message = ex.getMessage();
}

----------------------------------------------

The results... Nothing. Struggling to even find any logs to indication what might be happening. Any ideas anyone?

Thanks,
Mark.

 

Mark94
Kilo Expert

Ok, I do appear to be getting somewhere!

The "u_airwatch_import_table" table has a number of errors in it - "unable to resolve target record, coalesce values not present u_serialnumber”

There isn't actually any data yet...