Dynamically create import set fields based on JSON body

alexbones
Tera Expert

I'm am building out an REST integration that retrieves a JSON message from a system to grab device info and populate into the CMDB. 

I have set this up as a scheduled job to go and get the JSON message, but the trouble I'm running into now is how to make the import set dynamic as there is a section in the JSON body that could be different for each device found in the systemProperties. Is there a way to have the import set auto create new fields when ever a unique name is found? sort of like an LDAP setup where when you load the data it creates an import set field for each AD attribute found.

  "items": [
        {
            "id": 30,
            "name": "10.1.10.1.1",
            "displayName": "XXXXX",
            "deviceType": 0,
            "systemProperties": [
                {
                    "name": "system.sysinfo",
                    "value": "Microsoft Windows Server 2012 R2 Standard"
                },
                {
                    "name": "system.totalphysicalmemory",
                    "value": "4.00GB"
                },
                {
                    "name": "system.enablenetflow",
                    "value": "false"
                },

 

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Alex,

I would recommend you to go through about rest import set table API.

how large the json response would be?

Can you not consume their endpoint and get the json; iterate over it and populate in cmdb?

Regards

Ankur

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

Would the import set table API for a scheduled retrieval where we initiate it out of servicenow or is it setup to where the other system has an endpoint to send it into Servicenow?

Some responses could have several hundred or thousand devices. The setup is similar to the SCCM integration but using a rest call instead of JDBC.

I have been able to get the scheduled job to go and retrieve the message and populate an import set, but at this point it is all manually creating the fields in the import set instead of creating an import set field for each field it finds in the JSON message. Since there are many types of devices coming in with different field names, we are needing to figure out how to make this dynamic.

Rishabh Jha
Mega Guru

Hi Alex,

Were you able to figure this out? I want to achieve something similar, i.e. populate a custom table from a REST response, and don't want to manually map each field to the custom table fields, as the response could vary and there could be new fields added to the table. 

Please let me know if you've found any solution/workaround for your problem above, or have any suggestions.

Thanks,

Rishabh