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

Set the checkbox to false of a target field if the record is not in the load data sheet

SK41
Giga Guru

Hi,

 I have a requirement where I have to set the checkbox field to "false" for a target record when on the load data sheet that record does not come.

For example, for the first load, say we have loaded REC1, REC2 in target table. Now, if again I load the data, say, REC1, REC34. So, in this case the logic should set the checkbox for REC2 in target table as false, because in second load the same data did not come.

How can I achieve this requirement?

Hope, I can explain the requirement properly.

 

Please assist!

Thanks!

1 ACCEPTED SOLUTION

Sainath N
Mega Sage

@SK41 : You can achieve the following in the following way:.

 

1. Configure an OnAfter transform script in your transform map with the below code that captures the target record sys_id's that this execution touched. You will have an array of Sys IDs from this step.

 

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

    if (!import_set.coalescedIds)
        import_set.coalescedIds = [];
    import_set.coalescedIds.push(target.getUniqueValue());

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

 

2. Configure an OnSubmit transform script in your transform map with the below code to look out for the other records in the table that this transform map execution did not touch.

 

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

    var gr = new GlideRecord('YOUR_TABLE_NAME');
    gr.addQuery('sys_id', 'NOT IN', import_set.coalescedIds.join(',')); // This filters out the records that this transformation touched
    gr.setValue('YOUR_CHECK_BOX_FIELD', false);
    gr.setWorkflow(false);
    gr.updateMultiple();

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

 

If you are using workplace safety delivery applications in your instance, you will have this similar logic in the "Space Transform Map" transform map.

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

View solution in original post

7 REPLIES 7

AshishKM
Kilo Patron
Kilo Patron

Hi @SK41

Write onComplete transform script which will execute at the end of an import after all rows are read and transformed, in the script you can check which record updated by this transform map you can exclude those record and update the flag. 

 

AshishKMishra_1-1703102359624.png

 

-Thanks,

AshishKMishra


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

how can I check in the script which all records updated?

Sainath N
Mega Sage

@SK41 : You can achieve the following in the following way:.

 

1. Configure an OnAfter transform script in your transform map with the below code that captures the target record sys_id's that this execution touched. You will have an array of Sys IDs from this step.

 

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

    if (!import_set.coalescedIds)
        import_set.coalescedIds = [];
    import_set.coalescedIds.push(target.getUniqueValue());

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

 

2. Configure an OnSubmit transform script in your transform map with the below code to look out for the other records in the table that this transform map execution did not touch.

 

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

    var gr = new GlideRecord('YOUR_TABLE_NAME');
    gr.addQuery('sys_id', 'NOT IN', import_set.coalescedIds.join(',')); // This filters out the records that this transformation touched
    gr.setValue('YOUR_CHECK_BOX_FIELD', false);
    gr.setWorkflow(false);
    gr.updateMultiple();

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

 

If you are using workplace safety delivery applications in your instance, you will have this similar logic in the "Space Transform Map" transform map.

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Hi,

There is another part of this requirement, where I have to delete the records from target table, if those records are not coming through the import.

 For example, for the first load, say we have loaded REC1, REC2 in target table. Now, if again I load the data, say, REC1, REC34. So, in this case the logic should delete REC2 from target table, because in second load the same data did not come.

 

How can I achieve this?