Transform Map script

Deepa12
Tera Contributor

Hi,

 

Please let me know the correction in the script, i have written this script into transform map itself.

if the state is not retired than the import will update matching CI name and class and the target will not overwritten empty value.  
(function transformRow(source, target, map, log, isUpdate) {


    // Add your code here
    var name = source.u_ci_name;
    var configclass = source.u_ci_class;

    if (name == "" || configclass == "") {
        ignore = true;
    }

    var grSource = new GlideRecord("cmdb_ci");
    grSource.addEncodedQuery("sys_class_name=" + configclass + "^name=" + name);
    grSource.query();
    if (grSource.next()) {

        if (grSource.operational_status == "6") {
            ignore = true;
        }
    }
})(source, target, map, log, action === "update");
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Deepa12 

if you want to ignore the row based on the State, then you should use onBefore transform script and not onAfter

something like this

(function transformRow(source, target, map, log, isUpdate) {

    // Add your code here
    var name = source.u_ci_name;
    var configclass = source.u_ci_class;

    if (name == "" || configclass == "") {
        ignore = true;
    }

    var grSource = new GlideRecord("cmdb_ci");
    grSource.addEncodedQuery("sys_class_name=" + configclass + "^name=" + name);
    grSource.addEncodedQuery("operational_status=6");
    grSource.query();
    ignore = grSource.hasNext();

})(source, target, map, log, action === "update");

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

4 REPLIES 4

GlideFather
Tera Patron

Hi @Deepa12 

 

and what do you want to correct? Have you tried it? Any logs? What does it do and what do you want to do differently? Also please provide more details about the transform script and the whole process

 

EDIT: I can see that the query is built on name, it shall be on sys ID as the name can be duplicated

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


Bhuvan
Mega Patron

@Deepa12 

 

Rather than this, create a onBefore Transform script to check for ignore conditions and try it.

 

Thanks,

Bhuvan

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Deepa12 

if you want to ignore the row based on the State, then you should use onBefore transform script and not onAfter

something like this

(function transformRow(source, target, map, log, isUpdate) {

    // Add your code here
    var name = source.u_ci_name;
    var configclass = source.u_ci_class;

    if (name == "" || configclass == "") {
        ignore = true;
    }

    var grSource = new GlideRecord("cmdb_ci");
    grSource.addEncodedQuery("sys_class_name=" + configclass + "^name=" + name);
    grSource.addEncodedQuery("operational_status=6");
    grSource.query();
    ignore = grSource.hasNext();

})(source, target, map, log, action === "update");

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Shashank_Jain
Kilo Sage

@Deepa12 ,

 

Could you please provide the logs or any error details? That would help in understanding and diagnosing the issue more effectively.

Thanks!

If this works, please mark it as helpful/accepted — it keeps me motivated and helps others find solutions.
Shashank Jain