How to create a new record when no match found

Patrik Z
Giga Guru

Hello,

the client asked for a capability to Import New Vulnerable Items by a spreadsheet. A transform map has been created for that and now the next requirement is that if the Configuration Item is not found then a new one is created under the "Unclassed Hardware" class.

Since there are several ways to trigger a script in a transform map, I don't know which one to use:

  1. Transform Script and what type
  2. Source Script for the CI field
  3. or Script on the Transform map record (the one that appears when you check "Run script")

Does anybody know which one to use and how to begin, please?

Thank you, guys.

Patrik

1 ACCEPTED SOLUTION

Chris McDevitt
ServiceNow Employee
ServiceNow Employee

Hi,

Here is an outline of how to do this:

1. Using a Transform Map, map as many fields as possible.

find_real_file.png

 

2. Create an On-before Transform Script and place all of your heaving liftings into a Script Include

find_real_file.png

3. You need to do a look-up and get a match for the Vulnerability and the Configuration Item

find_real_file.png

(Advanced / Optional) Here is how you can leverage CI Lookup Rules while you are trying to match on a CI:

https://gist.github.com/cmcdevitt/72033b66335c2ab00af30214f76e4c2e

I would take a half hour and read through the docs on Import Sets:

https://docs.servicenow.com/bundle/tokyo-platform-administration/page/administer/import-sets/reference/import-sets-landing-page.html

 

 

 

 

View solution in original post

4 REPLIES 4

Community Alums
Not applicable

You can use the Source script for this. 

In your source script you can look for the CI record by passing the source value if the record exists you can return the corresponding sysid ,

else you can have the logic to insert the record in source script and return the sysid of new record after the insert. 

 

Maik Skoddow
Tera Patron
Tera Patron

Hi

I always found the following page helpful when deciding which kind of script to use: https://docs.servicenow.com/en-US/bundle/sandiego-platform-administration/page/script/server-scripti...

Maik

Chris McDevitt
ServiceNow Employee
ServiceNow Employee

Hi,

Here is an outline of how to do this:

1. Using a Transform Map, map as many fields as possible.

find_real_file.png

 

2. Create an On-before Transform Script and place all of your heaving liftings into a Script Include

find_real_file.png

3. You need to do a look-up and get a match for the Vulnerability and the Configuration Item

find_real_file.png

(Advanced / Optional) Here is how you can leverage CI Lookup Rules while you are trying to match on a CI:

https://gist.github.com/cmcdevitt/72033b66335c2ab00af30214f76e4c2e

I would take a half hour and read through the docs on Import Sets:

https://docs.servicenow.com/bundle/tokyo-platform-administration/page/administer/import-sets/reference/import-sets-landing-page.html

 

 

 

 

Abhijit4
Mega Sage

I think in your case, its better to have onBefore script as script will create entry in ci table and your field map will map it properly as record will be there in table while mapping.

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit
Community Rising Star 2022

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP