The CreatorCon Call for Content is officially open! Get started here.

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

Good point. If you don't know what values are being updated, then just throw the whole 'current' object at it.


I tried passing the current object to JSON.stringify() method but was unable to get anything.



The output I am getting does not have any value in it.



{"asset":{},"asset_tag":{},"assigned":{},"assigned_to":{},"assignment_group":{},"attributes":{},


"can_print":{},"category":{},"change_control":{},"checked_in":{},"checked_out":{},"comments":{},"company":{},


"correlation_id":{},"cost":{},"cost_cc":{},"cost_center":{},"default_gateway":{},"delivery_date":{},


"department":{},"discovery_source":{},"dns_domain":{},"due":{},"due_in":{},"fault_count":{},"first_discovered":{},


"fqdn":{},"gl_account":{},"hardware_status":{},"hardware_substatus":{},"install_date":{},"install_status":{},


"invoice_number":{},"ip_address":{},"justification":{},"last_discovered":{},"lease_id":{},"location":{},


"mac_address":{},"maintenance_schedule":{},"managed_by":{},"manufacturer":{},"model_id":{},"model_number":{},


"monitor":{},"name":{},"operational_status":{},"order_date":{},"owned_by":{},"po_number":{},"purchase_date":{},


"schedule":{},"serial_number":{},"short_description":{},"skip_sync":{},"start_date":{},"subcategory":{},


"support_group":{},"supported_by":{},"sys_class_name":{},"sys_created_by":{},"sys_created_on":{},"sys_domain":{},


"sys_domain_path":{},"sys_id":{},"sys_meta":{"active":"1","array":"0","attributes":"","audit":"1",


"calculation":"","choice":"1","choice_field":"","choice_table":"","create_roles":"","default_value":"",


"delete_roles":"","dependent":"","dependent_on_field":"","display":"name","dynamic_creation":"0",


"dynamic_creation_script":"","dynamic_default_value":"","dynamic_ref_qual":"","element_reference":"0",


"filterable":"1","foreign_database":"","groupable":"1","help":"","hint":"","i18n_sortable":"1",


"internal_type":"collection","label":"Hardware","language":"en","mandatory":"0","matchable":"1",


"max_length":"40","multi_text":"0","name":"cmdb_ci_hardware","plural":"Hardware","primary":"0",


"read_only":"0","read_roles":"","reference":"","reference_cascade_rule":"","reference_floats":"0","reference_key":"",


"reference_qual":"","reference_qual_condition":"","reference_type":"","sizeclass":"0","sortable":"1",


"spell_check":"0","staged":"0","sys_package":"fa8203b14f312200667fb3728110c78a","sys_scope":"global",


"table_reference":"0","text_index":"0","type":"0","type_description":"collection","unique":"0","url":"",


"url_target":"","use_dynamic_default":"0","use_reference_qualifier":"simple","virtual":"0","widget":"",


"write_roles":"","xml_view":"0"},"sys_mod_count":{},"sys_tags":{},"sys_updated_by":{},"sys_updated_on":{},


"unverified":{},"vendor":{},"warranty_expiration":{}}



Can you help with this?



Thanks


Anuneeti


Did the payload match the format given in the example with an items array, the classname is the first property of the array element, then your current object is attributed to the values property? That's that little bit of 'header' info you have to get. You cannot just throw current at it apparently.


Hey Chuck, I am unable to figure out how to proceed at this. Can you help me with using the JSON.stringify() method with current object.



Thanks


Anuneeti


Sorry for the delayed response. I was out of the office for a few days with no connectivity. At this point I do not have any ideas. I recommend trying customer support if nobody else in the community has anything.



HI Service Portal - ServiceNow


Contact Support | ServiceNow