How to convert the Transform map source object into JSON String?

Rajesh42
Tera Contributor

I am trying to convert the source object values to a json string in the transform script of Import set table. I dont find any promising input from servicenow documentation.

2 REPLIES 2

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Rajesh, what have you tried so far and what is the overall requirement you're trying to achieve here?

Rajesh42
Tera Contributor

Hi Brad,

I am trying to call the IRE engine from transform script of Import set table(Scoped Application). As per the documentation link, i have implemented the same script in my import set table transform map script area. 

var payload = {items: [{className:'cmdb_ci_linux_server', 
               values: {name:'stry0900844 CI 2',
                        serial_number:'9876EFGH',
                        mac_address:'4653XYZ',
                        ip_address:'10.10.10.4',
                        ram:'1238'}}]
              };

var jsonUntil = new JSON();
var input = jsonUntil.encode(payload);
var output = sn_cmdb.IdentificationEngine.createOrUpdateCI('ServiceNow', input);
gs.print(output);

In the above script, instead of getting each attribute name value pair from the source object, I am trying to convert the source object to JSON string so that way I can pass the converted JSON string for to make it work.

I tried the following but no luck.
var payload = {items: [{className:'cmdb_ci_linux_server', 
               values: source}]
              };

var jsonUntil = new JSON();
var input = jsonUntil.encode(payload);
var output = sn_cmdb.IdentificationEngine.createOrUpdateCI('ServiceNow', input);
gs.print(output);
Thank you,
Rajesh