Transform Map, How to update a field in a row even if has no values changed.

ican
Tera Contributor

Use Case:

Field Map:

ID (Coalesce)
Name

 

After executing transform map, I want to update a Comment field even though it was not updated during the transform due to No Value Changes.

 

How can I do this?

 

Thanks

1 ACCEPTED SOLUTION

Anil Lande
Kilo Patron

Hi,

You can use below logic.

Create onAfter transform script and use below script logic to update comments:

 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

    if (source.sys_import_state == 'ignored') {
        var recGr = new GlideRecord('incident');  // replace your table name
        recGr.addQuery('sys_id', target.sys_id.toString()); 
        recGr.query();
        if (recGr.next()) {
            recGr.comments = "Record is skipped during upload";
            recGr.update();
        }
    }

})(source, map, log, target);

 

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

2 REPLIES 2

Anand Kumar P
Giga Patron
Giga Patron

Hi @ican ,

Have one more mapping for sys_updated field and set its value with a script gs.now(). By adding this new mapping, the system will make sure the record is updated every time when the record is imported irrespective of any value changed or not.

But I wouldn't recommend it for huge data imports on daily scheduled jobs as it will have a huge impact on performance.

Mark it as helpful and solution proposed if it serves your purpose.

Thanks,

Anand

Anil Lande
Kilo Patron

Hi,

You can use below logic.

Create onAfter transform script and use below script logic to update comments:

 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

    if (source.sys_import_state == 'ignored') {
        var recGr = new GlideRecord('incident');  // replace your table name
        recGr.addQuery('sys_id', target.sys_id.toString()); 
        recGr.query();
        if (recGr.next()) {
            recGr.comments = "Record is skipped during upload";
            recGr.update();
        }
    }

})(source, map, log, target);

 

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande