How to populate company value from user table on incident form automatically ?

Ujjwala1
Tera Contributor

Hello Experts,

I have created a transform map which is linked to the import set table, in the run as script section I have written code to populate some fields at the time of ticket creation except company, script is taking every other field value,

Since I am working in MSP env, the script is automatically taking random field value for the company field which is a dot walked field from the user table, Could anyone suggest to me how should I fix that up?

Table Transform map: Data upload for tickets

Target table: Incident[incident]

run script : yes

script: 

var cafe = new GlideRecord('u_store');
cafe.addQuery('u_store_number', source.u_store_name);
cafe.addQuery('sys_domain', '');
cafe.query();
if (cafe.next()) {
    var sys_id = cafe.sys_id;
    var gr=new GlideRecord('sys_user');
    gr.addQuery('active',true);
    gr.addQuery('sys_domain','');
    gr.addQuery('company','');
    gr.query();
    if(gr.next())
        {
            
    target.company = '';
    target.sys_domain = '';
    target.u_store = sys_id;
    target.short_description = "Testing Tickets";
    target.category = "";
    target.u_type = "";
    target.u_item = "";
    target.assignment_group = "";
    target.contact_type = "email";

}
}

Any kind of help here is much much appreciated!

Thanks & Regards,

Ujjwala

1 ACCEPTED SOLUTION

Tony Chatfield1
Kilo Patron

Hi, can you clarify your issue, you are trying to prevent company from being populated? or it is being populated but by wrong value?
You indicate that you are running your script in the 'Run script section of the transform map?
To populate data into your target table I would move the script to a beforeTransfrom() script, so that it runs once for each row in your import, if that doesn't fix your issue then I would recommend adding some logging to confirm\validate your script functionality and the values set by the transform.

View solution in original post

6 REPLIES 6

Mohith Devatte
Tera Sage
Tera Sage

Hello @Ujjwala  can you try writing the script in on after transform script and try ?

Hi @Mohith Devatte ,

I have tried like that, still not working

@Ujjwala so your issue is some random company is being mapped but not the one which is there in staging table or source table ?

if not after can you try onBefore script?

can you share the script also once here?

Tony Chatfield1
Kilo Patron

Hi, can you clarify your issue, you are trying to prevent company from being populated? or it is being populated but by wrong value?
You indicate that you are running your script in the 'Run script section of the transform map?
To populate data into your target table I would move the script to a beforeTransfrom() script, so that it runs once for each row in your import, if that doesn't fix your issue then I would recommend adding some logging to confirm\validate your script functionality and the values set by the transform.