Transform map picking random attachment

Anna_Servicenow
Tera Guru

We have a task form and when user attaches an excel with a constant name "x_fdrbl_quality_control.csv", and click on import button, it will run a transform map and the entries in the excel will be listed in the task.

Now there are multiple people doin this activity at same time and the file name has to be constant. What is happening now is if the attached excel to the task has 5 rows, sometimes, after the transform map is run, it will show some 25 record including this and others from other attachment. How to fix this

below is my field map script

Anna_Servicenow_0-1725453810506.png

answer = (function transformEntry(source) {

    // Add your code here
gs.info("Entering transformEntry function");
    if (source.u_parent_id == "") {

        var tset_sys_id = target.parent_id;
        gs.info("Initial tset_sys_id: " + tset_sys_id);
       

        var gr2 = new GlideRecord("sys_attachment");
        gr2.addQuery("table_name", "x_fdrbl_business");
        gr2.addQuery('file_name', 'x_fdrbl_quality_control.csv');
        gr2.orderByDesc('sys_created_on');
        gr2.setLimit(1);
        gr2.query();
        gs.info("Query executed, records found: " + gr2.getRowCount());
        while (gr2.next()) {
            gs.info("Attachment sys_id: " + gr2.sys_id);
            gs.info("Attachment table_sys_id: " + gr2.table_sys_id);
            //tset_sys_id = gr2.table_sys_id;
            var gr = new GlideRecord("x_fdrbl_business");
            gr.addQuery("sys_id", gr2.table_sys_id);
            gr.query();
            if (gr.next()) {
                tset_sys_id = gr2.table_sys_id;
                gs.info("Updated tset_sys_id: " + tset_sys_id);
            }
        }

    }
    gs.info("Exiting transformEntry function");
    gs.info("Final tset_sys_id: " + tset_sys_id);
    return tset_sys_id; // return the value to be put into the target field
})(source);



 

 

4 REPLIES 4

Anurag Tripathi
Mega Patron
Mega Patron

Hi Anna,

 

Can you add logs to all GlideReocrd inside if conditions to se what scripts are running and how many times. 

-Anurag

Can you please help

 

Actually you have the info messages, do you see them when this runs?

 

-Anurag

Below are the logs I put and output Inline(It working fine, sometime this breaks like when multiple people are importing at same time or system is importing multiple csv)

 

answer = (function transformEntry(source) {

    // Add your code here

    if (source.u_parent_id == "") {

        var tset_sys_id = target.parent_id;
        var gr2 = new GlideRecord("sys_attachment");
        gr2.addQuery("table_name", "x_fdrbl_business");
        gr2.addQuery('file_name', 'x_fdrbl_business_quality_control.csv');
        gr2.orderByDesc('sys_created_on');
        gr2.setLimit(1);
        gr2.query();
        gs.info("Query executed, records found: " + gr2.getRowCount()); // gives count 1
        while (gr2.next()) {
       
            gs.info("Attachment table_sys_id: " + gr2.table_sys_id); // gives the sys_id 
            //tset_sys_id = gr2.table_sys_id;
            var gr = new GlideRecord("x_fdrbl_business");
            gr.addQuery("sys_id", gr2.table_sys_id);
            gr.query();
            if (gr.next()) {
                tset_sys_id = gr2.table_sys_id;
                gs.info("Updated tset_sys_id: " + tset_sys_id); eturned value
            }
        }

    }

    return tset_sys_id; // return the value to be put into the target field
})(source);