Import Sets 2 Source Records to 1 Target Record

kemmy1
Tera Guru

Hello!

I'm trying to create or coalesce 2 source import set records to 1 target record.

I got a cool script to do this (see below), but my issue is that my source records do not have a common source Classification field.

 

Here's what I want to do:

Source Record  Target Record 
FacilityClassification FacilityClassification Name
ABC1 ABCLow
ABC2   
     
ABC3 ABCHigh
ABC4   
     
XYZ1 XYZLow
XYZ2   
     
XYZ3 XYZHigh
XYZ4   

 

So, then I created a new column on the import set table called "Classification Name" and I'm trying with a "onBefore" Insert/Update business rule to update this new column to set the records with 1 and 2 Classification Name to "Low" for example.

 

The column gets set when I manually update the record, but not when I kick of the import (the business rule should kick off on import right?)

 

Here's my business rule script:

var classification = current.u_classification;
 
    switch (classification .toString()) {
        case '1':            
            current.classification_name= 'Low';
            break;
        case '2':
            current.classification_name= 'Low;
            break;
        case '3':
           current.classification_name= 'High';
            break;
        case '3':
            current.classification_name= 'High';
            break;
       }

 

Here is the script (starting of it) that I'm using for my transform map.  It's an onbefore transform map script and I'm not mapping any fields (just FYI):

 

var sourceTable = new GlideRecord(source.getTableName());
    sourceTable.addQuery("u_dtf_id", source.u_dtf_id.toString());
    sourceTable.addQuery("sys_import_set=" + source.sys_import_set.toString());
    sourceTable.addQuery("sys_import_state=inserted");
    sourceTable.query();

    if (sourceTable.next()) {
        var targetTable = new GlideRecord(target.getTableName());
        if (targetTable.get(sourceTable.sys_target_sys_id.toString())) {
            targetTable.detloc += "," + source.u_dtf_id.toString();
            targetTable.update();
        }

        ignore = true;
    } else {
        target.detloc = source.u_dtf_id.toString();
        //target.TARGET_FIELD_FOR_FIELD_EXT = source.FIELD_EXT.toString();
    }

 

 

0 REPLIES 0