Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

https://community.servicenow.com/community?id=community_question&sys_id=d365659d1bcc64d03222ea89bd4bcbae 

please redirect to this question it will very helpful if u guide me thanks in advance