Reputation: 1
I created my rest api with node and typescript, but since I have no knowledge of SCCM, I need to understand if it would be possible to make this integration for ServiceNow to consume this api.
I need to create a dropdown list of free software in servicenow so that my company's employees can download it without having to open a ticket.
problem 1: company SN integration hub is Start
that's why the reason for creating this api, so that sccm can communicate with SN by sending commands (or something else I don't know) so that in SN the employee can download and install it without needing permission from support to complete the installation.
i have no idea what to do
edit ( Perhaps I have not clearly specified that the problem with my integration is understanding how to integrate my Rest API with SCCM/System Center, as my goal is to call the free license software that the company has and send it to ServiceNow when requeste )
Upvotes: 0
Views: 679
Reputation: 767
To import data into ServiceNow, you normally use Import Sets (Data Sources, Transform Maps, and schedules). For the Data Source, specify a script like this:
/* global gs, sn_ws */
(function loadData( import_set_table ) {
var me = 'my_function_name';
import_set_table.addColumn('hostname', 50);
import_set_table.addColumn('serial', 50);
import_set_table.addColumn('ip', 50);
try {
var rm = new sn_ws.RESTMessageV2('rest_message_name', 'method_name');
rm.setEccParameter('skip_sensor', 'true'); // prevent Discovery sensors from gobbling-up the ECC input
// Set correlation ID for ECC, so we can find it in the logs
var guid = gs.generateGUID();
rm.setEccCorrelator(guid);
rm.setQueryParameter('hostname', value);
var result = rm.execute();
var json = result.getBody();
var parsed = JSON.parse(json);
var map = {
hostname: parsed.hostname,
serial: parsed.serial,
ip: parsed.ip,
};
import_set_table.insert(map);
gs.log('complete', me);
}
catch ( err ) {
var errorMessage = err.getMessage() || err.message;
gs.error('ERROR : ' + errorMessage, me);
}
})(import_set_table);
Then you can use magic in your Transform Map to sync the values in the Import Set to a permanent table. You can either map each row (normal) or ignore each row:
/**
* Do not import rows - all transformation is done onComplete
*/
(function transformRow() {
/* nothing to import directly - actions happen onComplete */
ignore = true;
})();
...and use an onComplete script (or other type) to manipulate the data by hand. This site has a very easy to follow guide on how rows/sets are transformed.
Upvotes: 0
Reputation: 767
I do something similar - I have a node-based API gateway on our local network that I call from a Scripted REST API. Then, I can use an HTTP call to the "local" ServiceNow instance (something like /api/namespace/api_id/resource_name
) from anywhere (UI Builder, Flow, Workflow, etc.).
In this example, I'm using a previously defined REST Message, but you could also follow the docs to set location, auth, headers, and params in code (if you don't want to define yet another record.
function search( value ) {
var rm = new sn_ws.RESTMessageV2('rest_message_name', 'method_name');
rm.setEccParameter('skip_sensor', 'true'); // prevent Discovery sensors from gobbling-up the ECC input
// Set correlation ID for ECC, so we can find it in the logs
var guid = gs.generateGUID();
rm.setEccCorrelator(guid);
rm.setQueryParameter('hostname', value);
var result = rm.execute();
var json = result.getBody();
return JSON.parse(json);
}
Use this function in your Scripted REST API and pass/parse the results appropriately.
var results = search('some_value');
res.setStatus(200);
res.setBody(results);
Upvotes: 0