Creating models on data import
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2022 05:32 PM
Working with data import for computer assets. In the Transform map, I have an onBefore script to handle making the Model for the Computer if one does not already exist. Not all the script included here, as not relevant to parsing make/model/number out of the input data, and all that is tested working fine. The issue is, SN isn't actually making the Model entry, but it's not erroring to explain why. Running as a test in Background Scripts, it pretends everything worked as I see this output:
*** Script: Scheduling: Generate Assets: MacPro (MacPro4,1) for: 2022-11-22 19:53:26
my gs.info tells me: should be Apple Inc. MacPro (MacPro4,1)
So one issue is the display_name is not getting made properly. The other issue is, it's not making the entry in the model table at all. I'm not sure why it says "generate assets" though either. Here is the portion of the script that should be making the entry:
var grNew = new GlideRecord("cmdb_model");
grNew.initialize();
grNew.name = model;
grNew.sys_created_by = "AllSight";
grNew.manufacturer = manu;
grNew.cmdb_model_category = "Computer";
grNew.insert();
gs.info("should be "+manu+" "+model);
Seems pretty straight forward, and I've used similar method to create User records with no issue. So why won't it actually make the model record?
I'm trying to do it this way so the model is made "properly" because if you just let import create models from what is put in the model field, they lack manufacturer and then proper display name (calculated manufacturer and model name together). That in turn creates other asset management issues as the asset record isn't made properly for the computer record. Wish this wasn't so darned complicated...
So, any thoughts or advice why this isn't working and how to make it create these records would be greatly appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 01:15 PM
Hi @Yadin ,
Since the manufacturer is a reference field, that will expect a sys id when writing through background script so you can glide record the core company table and pass the name and then get sys id of it and then give this sys id in the script then it will update the manufacturer. But if you are loading the data then using transform maps is the best way for it. If you are going through script then use sysid's of records instead of name for reference type of field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2022 10:44 AM
That is an important bit of information. I didn't know that the "front end" method would do the expected lookup, but the "back end" method was unable to do that so you have to use the sys_id not the Name. Makes sense now why there was no error, though I'd assert informationally the log should have said something like "no sys_id found for Dell Inc." which would have at least indicated what was happening.
As you say, I've gone the transform route which has had some added benefits as well. The other platform limitations are still issues, but at least an onBefore script to try to avoid duplicate entries helps. The fact that Display Name is the primary field but includes by design/intent the Manufacturer is still annoying because you have redundant information to the actual Manufacturer field. Seems there is no way to display the Name field of the Model instead in a Computer record, and overriding the Display Name to just be Name appears to not be advised.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2022 12:35 PM
Hi @Yadin ,
Yes transform maps works the best way. Sorry i didnt get what you want at the end regarding Name/model etc. If you want to see the name on asset record then you can configure form layout and add 'Name' field from model form and you can add the same in list view also. Altering the display name might not be the best way to do that
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2022 12:39 PM
Yeah I tried that option, but the column/field is called Name instead of Model, and I can't find any way to rename the field just on the form or list view. I can change the label of a field in a form for a table that I'm managing in my app, but I don't want to globally re-label this field for obvious reasons, just show the "proper" name in the view. If you know a trick for that I'm all ears!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2022 12:43 PM
if you want to rename it for entire Hardware table then you can try dictionary override for that field. But in all my projects i didnt encounter any client facing this issue, Model is the correct of doing it as it includes the manufacturer name as well. Iam not sure why you dont want to use Model and just want to see the Name of the model, is there any particular reason?