- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2020 01:08 PM
Hello!
I'm trying to create a fix script that will create CI records on assets (alm_asset) that do not have a CI.
I'm using this Business Rule and Script Include to aid me in actually creating the CI.
https://<instance-name>.service-now.com/nav_to.do?uri=sys_script.do?sys_id=26ebfeef1b3210002502fbcd2c07136f https://<instance-name>.service-now.com/nav_to.do?uri=sys_script_include.do?sys_id=19c0f3603703100044e0bfc8bcbe5d9b
Here is my script below. I'm basically searching for all of my assets then going to loop though each calling the script include to create the CI for each.
var queryStr = 'ciISEMPTY^model_category!=fed01818db93ff00c0ede66505961962^ORmodel_category=NULL^model_category!=996b568ec3102000b959fd251eba8f19^model_category!=218323293743100044e0bfc8bcbe5d61^model_category!=35bf2d4137101000deeabfc8bcbe5dbd^model_category!=c9d5bc50c3031000b959fd251eba8fbc^model_category!=83c92540732623008b516cb63cf6a7b1^model_category!=58fdb454c3031000b959fd251eba8ff0';
var assets_no_ci = new GlideRecord('alm_asset');
//assets_no_ci.addEncodedQuery(queryStr); //Commented to test with a single record
assets_no_ci.addQuery('serial_number', '1234567890'); //test this script with a single record
assets_no_ci.orderBy('model_category');
assets_no_ci.query();
while (assets_no_ci.next()) {
(new AssetandCI()).createCI(assets_no_ci);
gs.log("Adding CI to Asset: " + assets_no_ci.display_name);
}
However when I run the script it gives me an error:
*** Script: Asset count: 1
Evaluator: org.mozilla.javascript.EvaluatorException: GlideRecord.insert() - invalid table name: null (sys_script_include.19c0f3603703100044e0bfc8bcbe5d9b.script; line 180)
EvaluatorException(JavaScript evaluation error on:
var queryStr = 'ciISEMPTY^model_category!=fed01818db93ff00c0ede66505961962^ORmodel_category=NULL^model_category!=996b568ec3102000b959fd251eba8f19^model_category!=218323293743100044e0bfc8bcbe5d61^model_category!=35bf2d4137101000deeabfc8bcbe5dbd^model_category!=c9d5bc50c3031000b959fd251eba8fbc^model_category!=83c92540732623008b516cb63cf6a7b1^model_category!=58fdb454c3031000b959fd251eba8ff0';
var assets_no_ci = new GlideRecord('alm_asset');
//assets_no_ci.addEncodedQuery(queryStr); //Commented to test with a single record
assets_no_ci.addQuery('serial_number', '1234567890'); //test this script with a single template
assets_no_ci.orderBy('model_category');
assets_no_ci.query();
while (assets_no_ci.next()) {
(new AssetandCI()).createCI(assets_no_ci);
gs.log("Adding CI to Asset: " + assets_no_ci.display_name);
}
)
[0:00:00.055] Total Time
Any thoughts or help would be appreciated.
Thanks!
Dom
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2020 09:53 AM
so that's the issue, it doesn't know on what cmdb_ci table to create the CI's. This value should be stored in the model category and is what the following does. it dot walks to the value
ciClass = asset.model_category.cmdb_ci_class.toString();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2020 09:47 AM
The log statement you added returned undefined. I'll keep on poking around at it to see where I get.
Yash below had suggested adding sys_id when calling the function. This seemed to have fixed the error however the asset is not updated with a CI still.
*** Script: Class being used as reference table value is:
*** Script: Adding CI to Asset: Microsoft Corporation Surface Laptop 3
[0:00:00.072] Total Time

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2020 09:53 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2020 10:09 AM
Out of curiosity would having the model_category field as a list type and not reference type cause it not to find the cmdb_ci_class? This I believe was our original issue as to why we have to clean these assets up. We had a change a while back (not by me!) that made the model category field a list type from the reference type and it broke a lot of things.
I think making that change in our dev instance will probably get this working. I'll test this out and report back. Thank you again for all the help - leaning stuff every day still!
Dom

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2020 10:28 AM
Ah Dom you poor guys, what terrible person changed the field type!
Yes that will the reason, it's likely a completely different field name with a u_ prefix so ServiceNow hasn't a clue.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2020 07:28 AM
Hello User,
Why are taking so much effort,Service already gave you OOTB business rule to create CI after updating Asset Record.
Why you are not using this from the above.
I hope you got my point.
Please Mark it helpful/correct if my answer helps in any way to resolve your query.
Reach out to me if any more help required.
Regards
Yash.K.Agrawal