Conditional transform maps for Import set API

sreedharkaliset
Mega Expert

Hi All,

I am trying to build an inbound web service(Import set API) which accepts a payload for CI table. Based on the sys class name given in the payload, it should insert the corresponding CI record.

I did create an inbound web service and mapped the Class attribute of cmdb_ci to the sys class name from the payload and the record is getting created.

Issue occurs where I send values specific to rack or any child table of cmdb_ci in payload. As the transform map is for cmdb_ci, all the fields on childs of cmdb_ci are not accessible in the transform map.

I was trying to check in community and docs if I could create multiple transform maps under same inbound web service and make them run based on conditions but I could not find any. If I give two transform maps under the web service, each map is creating one record which is not expected

Please suggest on how to overcome this.

Regards,

Sreedhar

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Sreedhar,



For the individual transform maps you create you can decide whether to perform the transformation or not using onBefore or onStart script.



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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

jarodm
Mega Guru

There are probably other ways to accomplish this, but here is mine:



  • Create multiple transform maps
  • On each one, create an onBefore rule
    • Have some condition to determine which records you DON'T want to process
    • On the excluded script, set "ignore = true;"
  • There will still be multiple records inserted into the import table, but will only get processed if they aren't ignored


I most commonly use this when import two types of records that need different coalesce settings based on table indexes or based on available source data.


Hi,



I tried ignore=true in on before transform scripts for both maps based on certain conditions.



If the record is ignored by first map and inserted by second map, the response is as shown below. Please let me know how to avoid all error map results and send only success map result in the response



{
  "import_set": "ISET0010091",
  "staging_table": "u_cmdb_load",
  "result": [
  {
  "transform_map": "CMDB load",
  "table": "cmdb_ci",
  "status": "error",
  "error_message": "Target record not found",
  "status_message": "Row transform ignored by onBefore script"
  },
  {
  "transform_map": "Rack",
  "table": "cmdb_ci_rack",
  "display_name": "name",
  "display_value": "TY345",
  "record_link": "https://xxx.service-now.com/api/now/table/cmdb_ci_rack/5945b5224f220300b6704e318110c7e4",
  "status": "inserted",
  "sys_id": "5945b5224f220300b6704e318110c7e4"
  }
  ]
}


Hi All,



Please let me know if anyone has faced similar issue before and how to overcome the issue