createOrUpdateCI

mathuranuneeti
Kilo Expert

Hi All,

We have a requirement of implementing CMDB Identification and Reconciliation in our instance, even when someone is manually creating or updating a CI.

I found on community that we can call a function createOrUpdateCI(source,input) for achieving this.

The function createOrUpdateCI() takes two input parameters, one of them being payload of the CI attributes. For this I require to convert the current record object into payload format. Is there any function with which we can convert current object to payload format as shown below:

items: [{className: 'cmdb_ci_server', values: {name: 'linux123', serial_number: '12srt567', ip_address: '10.2.3.4'}, }]}

Does anyone have any idea about this?

Thanks in advance.

Anuneeti

9 REPLIES 9

Chuck Tomasi
Tera Patron

That looks like JSON to me. Use the JSON.stringify() method.



Example:



var myObj = {'field' : 'value', 'another' : 'val'};



var s = JSON.stringify(myObj);


Hey Chuck,



Thanks for the reply.



If we want to use JSON.stringify() method, would it be required to pass all the fields and their values manually?


As we want this function to work on before-insert/update business rule. So we wont be able to identify which attributes are getting updated.



Kindly suggest how can we use it in this case.



Thanks
Anuneeti


Not being totally familiar with the function you mentioned... based on the usage you gave earlier, my answer is: Yes, you will need to construct the object (or pass it as an anonymous object.) I wouldn't stringify() the entire CI object.


Hi Chuck,


11.PNG


This is what we require to perform. You can see the payload in the right side. My concern here is when we want to use this function in a business rule, how will we get to know which attributes are getting updated, to add them to the json payload. This is the reason I was thinking of passing the current records object.


Could you suggest any way to achieve this?



Thanks


Anuneeti