Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

import list with list view

MaharshiC
Tera Contributor

Hi,

 

I have created a transform map and i have a site poc field which is list collector field reference to user in my target but a string in my source with email values separated by comma. Now when importing the data i want it to be mapped correctly. I have created a field mapping script but that is not working

answer = (function transformEntry(source) {

    var grp_type = '';
    var result = [];
    var inputArray = source.u_site_poc.split(',');
    var gtype = new ArrayUtil().unique(inputArray);
    for (var i = 0; i < gtype.length; i++) {
        var grpType = new GlideRecord('sys_user');
        grpType.addQuery('email', gtype[i]);
        grpType.query();
        if (grpType.next()) {

            grp_type = grpType.sys_id.toString() + ',';

        }
    }

 
	return usr.sys_id;

   

})(source);

 

MaharshiC_0-1744811256135.png

 

5 REPLIES 5

Robert H
Mega Sage

Hello @MaharshiC ,

 

Your function is trying to return a property of some "usr" object, which is not defined.

 

Please use the following script instead:

answer = (function transformEntry(source) {

	var result = [];
	var gr = new GlideRecord('sys_user');
	gr.addQuery('email', 'IN', source.u_site_poc);
	gr.query();
	while (gr.next()) {
		result.push(gr.getUniqueValue());
	}
 
	return result.toString();

})(source);

 

Regards,

Robert

Hi @Robert H ,

 

Will this work as my source is a string field separated by commas?It is just taking the first value

Hello @MaharshiC ,

 

Yes, the "IN" operator in addQuery() works with comma separated strings.

 

Input file:

RobertH_0-1744816986097.png

 

Target record after transformation:

RobertH_1-1744817017433.png

 

Regards,

Robert

Hi @Robert H ,

I tried the below code but still inserting just a single value but i can see in my staging string field both the values are there but it is not getting copied in my target list field

answer = (function transformEntry(source) {

	var result = [];
	var gr = new GlideRecord('sys_user');
	gr.addQuery('email', 'IN', source.u_site_poc);
	gr.query();
	while (gr.next()) {
		result.push(gr.getUniqueValue());
	}
 
	return result.toString();

})(source);