Best way to update only a few fields on an import record?

Mat Gdowski1
Tera Contributor

Hey all,

 

I'm working on a project, in Tokyo, where I need to update a set of records that are being brought in by a CSV import file utilizing a Transition Map.  So, I'm expecting to setup a Transition Map Script to try and do the following, but having a bit of trouble coming up with the best way to do this...

 

If the asset name is equal to a current asset name in the hardware asset table, then I ONLY want to update the fields that are NOT blank on the import table.  Example:

* Asset Name: Hardware1

* IP Address: 100.100.100.100

* Location: 

* Asset Type: 

* DNS Name: Hardware

 

So, I only want to update the Asset Name, IP Address and DNS Name on this particular record.  I need to ignore Location and Asset Type as they are blank.

 

Then I need to perform this action for every record on the import file.  (I'm guessing a FOR statement somehow?)

 

So, the issue I'm having is how exactly to script "updating" each record that has information but "skipping/ignoring" each record that is blank.  I'm guessing I can use a getElements() to get the array of what the fields are holding, but I don't know the best way to either save/update or ignore/skip the proper fields.  😕

 

Thoughts?  Ideas?

 

Thanks

1 ACCEPTED SOLUTION

Tony Chatfield1
Kilo Patron

Hi, I would not expect existing field content to be overwritten by a blank\empty value during update, unless the transform map 'Copy empty fields' == true, so setting this field to false/removing the tick should resolve this requirement.

 

If you are coalescing on the Asset Name, then in your transform script you can simply set some conditions when the action is update. Untested but something like

if(action == 'update') {
target.field1 = 'someHardCodedValue';
target.field2 = 'someOtherHardCodedValue';

//mapping a reference field
var recCheck = new GlideRecord('theReferncneTable');
if(recCheck.get('fieldReferencedInImportFile', source.importfFeldName)) {
target.fieldX = recCheck.sys_id;
}
}

View solution in original post

2 REPLIES 2

Tony Chatfield1
Kilo Patron

Hi, I would not expect existing field content to be overwritten by a blank\empty value during update, unless the transform map 'Copy empty fields' == true, so setting this field to false/removing the tick should resolve this requirement.

 

If you are coalescing on the Asset Name, then in your transform script you can simply set some conditions when the action is update. Untested but something like

if(action == 'update') {
target.field1 = 'someHardCodedValue';
target.field2 = 'someOtherHardCodedValue';

//mapping a reference field
var recCheck = new GlideRecord('theReferncneTable');
if(recCheck.get('fieldReferencedInImportFile', source.importfFeldName)) {
target.fieldX = recCheck.sys_id;
}
}

Tony,

 

Good point, I did forget about that.  However, how about if the information is the same in both the import table and the target table?  Should I just let it update it and it will be fine?  I guess my point is, I forgot to mention that they only wanted fields updated that have "changed".

 

Again, thank you for the info.  I will look into this.  🙂

 

Take care