Populating reference field using IRE API (Identification and Reconciliation engine)

Eric Therrien
Tera Expert

The goal is that I want to populate a reference field from one CI with the value (reference) of another CI from a single Identification and Reconciliation engine (IRE) payload.

 

Example

I have the following JSON payload (simplified) that I want to submit to the IRE:

 

{"items":[{"className":"some cmdb_ci class","values":{"name":"CI 1"},"internal_id":"1"},{"className":"some cmdb_ci class","values":{"name":"CI 2"},"internal_id":"2"}],"referenceItems":[{"referenceField":"custom_ci_reference_field","referenced":"2","referencedBy":"1"}]}

 

Don't worry about the two CIs item's exact values, just assume there is more data to it and that it get reconciliated properly. It does as they get created/updated just fine.

 

Now what I want is to have the field "custom_ci_reference_field" of "CI 1", wich is a cmdb_ci reference field, set to the sys_id to "CI 2".

 

As per the documentation (wich is really light on the subject), you should be able to add a reference Item object, such as {"referenceField":"custom_ci_reference_field","referenced":"2","referencedBy":"1"} to the referenceItems array and it should "work" by populating the field "custom_ci_reference_field" from "CI 1" with the sys_id of "CI 2" (from my understanding of the doc), but it's not.

 

Stuff I've tried or won't work for me:

  1. I can't get "CI 2" sys_id with a GlideRecord query, because "CI 2" might not exist yet.
  2. I tried switching the order and have "CI 2" being the first item in the items array of the payload, that did not work either.
  3. I tried using the related array property in the "CI 1", but that did not work.
  4. I did not tried the lookup array property, because it didn't seem to be my use case.
3 REPLIES 3

dannyfleer
Tera Contributor

Hi @Eric Therrien 

I wonder if you ever found a solution to this case?

I tried the same like you and could not get it to work 😞

dannyfleer
Tera Contributor

Hi @Eric Therrien 

I wonder if you ever found a solution to this case?
I tried the same as you and couldn't get it to work 😞

Community Alums
Not applicable

You need a related field for this payload to work. I have edited your payload as an example. 

{"items":[{"className":"some cmdb_ci class","values":{"name":"CI 1"},"internal_id":"1","related":[{"className":"some cmdb_ci class","values":{"name":"CI 2"},"internal_id":"2"}]}],"referenceItems":[{"referenceField":"custom_ci_reference_field","referenced":"2","referencedBy":"1"}]}

 

The other thing you need to do is check for an entry on the related list called "Related Entries" off the Identifier rule of the class being referenced. 

Example Service Offering has a reference field of "cmdb_ci_service" table, which means you need to make an entry on the Identifier for cmdb_ci_service that has a reference to the service offering table and the reference field.

PeterMueller_0-1752607859250.png

PeterMueller_1-1752607881715.png

Here is an example of the payload that would be sent.

{"items":[{"className":"cmdb_ci_service","internal_id":"E1ST9VLYI52FLN837KUA60JIW05OGNXA","related":[{"className":"service_offering","internal_id":"LN67FT6EXDEM0SPY8GMSEQL9CEMP2HKQ","sys_object_source_info":{"discovery_source":"Other Automated","source_feed":"example","source_native_key":"LN67FT6EXDEM0SPY8GMSEQL9CEMP2HKQ"},"values":{"name":"Service Offering"}}],"sys_object_source_info":{"discovery_source":"Other Automated","source_feed":"example","source_native_key":"E1ST9VLYI52FLN837KUA60JIW05OGNXA"},"values":{"name":"Service"}}],"referenceItems":[{"referenceField":"parent","referenced":"LN67FT6EXDEM0SPY8GMSEQL9CEMP2HKQ","referencedBy":"E1ST9VLYI52FLN837KUA60JIW05OGNXA"}],"relations":[]}