The CreatorCon Call for Content is officially open! Get started here.

how to if source field is empty add with previous value transform map

ABHAY_M
Tera Guru

Hi, 

I am trying to transform data with the below format. Is there a way to script in the previous records name, if the current record name is null during a transform?

Example:source  table

 image

Result:target table

image

it will a very helpfull thanks

1 ACCEPTED SOLUTION

Jon23
Mega Sage

Hi,

Use an onStart Transform script with the following code:

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

    var tmpName = '';
    var sourceTable = map.source_table;
    var importSet = import_set.sys_id;

    var sourceGR = new GlideRecord(sourceTable);
    sourceGR.addQuery('sys_import_set', importSet);
    sourceGR.orderBy('u_value1');
    sourceGR.query();

    while (sourceGR.next()) {
        if (sourceGR.u_name != 'null') {
            tmpName = sourceGR.u_name.toString();
        } else {
            sourceGR.setValue('u_name', tmpName);
            sourceGR.update();
        }
    }

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

View solution in original post

5 REPLIES 5

Narsing1
Mega Sage

You can use some thing like this in your "onBefore" Transform Script

if ((action == 'insert' || action == 'update') && source.Name == null))
  ignore = true;

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

try this

if( source.u_name == 'null'|| source.u_name == null)
  ignore = true;

Regards
Ankud

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Jon23
Mega Sage

Hi,

Use an onStart Transform script with the following code:

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

    var tmpName = '';
    var sourceTable = map.source_table;
    var importSet = import_set.sys_id;

    var sourceGR = new GlideRecord(sourceTable);
    sourceGR.addQuery('sys_import_set', importSet);
    sourceGR.orderBy('u_value1');
    sourceGR.query();

    while (sourceGR.next()) {
        if (sourceGR.u_name != 'null') {
            tmpName = sourceGR.u_name.toString();
        } else {
            sourceGR.setValue('u_name', tmpName);
            sourceGR.update();
        }
    }

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

 

perfectly working thank you thank you @jwalton  thank you very much wish u all the best.