How to update only changed fields when importing data
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 08:23 AM - edited 11-20-2023 08:24 AM
I'm trying to update fields that are already in the data source. The script we currently have keeps ignoring the update.
I'm trying to update the description field and the barcode field. These fields are currently empty.
I'm currently only coalesced to the asset name field. There is only one transform script, OnBefore.
Please see the attached for our current scripts.
Thank you!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 11:36 AM
Hi, unfortunately it's not possible to properly evaluate screenshots and the lack of example\reference data doesn't make it any easier.
Are your fields mapped correctly in your field mapping?
Have you disabled any 'abort' BR's to confirm that updates are made with fields mapped and no abort configured?
Have you tried moving your 'Table Transform Map' 'abort' script to a before transform script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 11:43 AM
Trying to update fields that are currently "empty" in an asset that is already in the data source.
I want the system to realize I'm only updating the fields that have changed and I want it to coalesce to the assets name. This data source was already designed to coalesce to "asset name".
I believe the script is preventing me from doing this, but I honestly little knowledge working with scripts.
Example:
Current
Asset: SP-2 Description: Empty Barcode: Empty
Desired state
Asset: SP-2 Description: HVAC Unit Barcode: 1234
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 01:00 PM
Hi, coalesce will occur as part of the transform if you have 1 or more mapped fields flagged as coalesce, there is no need for any other action for this behavior.
The platform will only update fields that have changed, there is no need to check or validate these unless you want to prevent an entire record from updating when specific field(s) are empty/null? (unless you have the transform 'Copy Empty fields' flagged true).
If you need to control logic for individual record updates, then you should add your code to 1 before transform script (so that it is applied on a per row \record basis).
// beforetransform script
var ignoreRow = false;
//ignore row if multiple source values are null
if(source.aField == '' || source.anotherField == '') {
ignoreRow = true;
}
//ignore row if referenceValue missing\incorrect
//optionally wrapped in condition to check if ignoreRow is already true
if(ignoreRow == false) {
//some script to check other table
var gr = new GlideRecord('sometable');
gr.addQuery('someField', 'someValue');
gr.query();
if(!gr.next()) {
ignoreRow = true;
}
}
ignore = ignoreRow;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 11:48 AM
Just looking at your Scripts - I would wager that the Transform Map script itself is the thing causing the issue here. Double-check your data that is coming into the Import Set, do you have values present for all the fields you are stating in your IF condition in the script? You could also put a log statement as soon as the onBefore Transform Script to see if it even gets to that part.