transform script is not working

chandan2212
Tera Contributor

Hi All, 

 

Could you please help me with the transform map script so that it works properly

 

 

 
answer = (function transformEntry(source) {
    var owners = source.u_owner_name || '';  
    if (!owners) {
        gs.info('TM Owners empty');
        return '';
    }

    var arr = owners.split(',');
    gs.info('TM Owners tokens=' + arr.length);

    for (var i = 0; i < arr.length; i++) {
        var userVal = (arr[i] || '').trim();
        if (!userVal) continue;

        var userGR = new GlideRecord('sys_user');
        userGR.addQuery('user_name', userVal);
        userGR.setLimit(1);
        userGR.query();

        if (userGR.next()) {
            gs.info('TM Matched user_name=' + userVal + ' -> ' + userGR.getDisplayValue());
           
            return userGR.name;
        } else {
            gs.info('TM No match for user_name=' + userVal);
        }
    }

   

    })(source);
3 REPLIES 3

GlideFather
Tera Patron

Hi @chandan2212,

 

can you possibly explain what's wrong with your code? it's not executed or the result is not staisfactory? It needs some context to give you meaningful response, pasting a random code is not sufficient.... :((

 

 

EDIT:

And what is supposed to be the || '' part in

var owners = source.u_owner_name || '';  

 

What do the logs give you? Shouldn't it be just "var owners = source.u_owner_name;"???

_____
No AI was used in the writing of this post. Pure #GlideFather only

MadhanMaddy
Tera Contributor

Hi @chandan2212 ,

Can you please let me know what you're getting once you're loading or running this data (I mean which log/info message the script is populating or it's not running at all). 

Also, If you could share a sample data/obj of how the owners array/object is going to look like it'll be easy for me to test more & provide you with a fix soon. 

where are you writing this script? Is it in the transform map run script or transform script(before, after..) or field mapping source script?

 

Sandeep Rajput
Tera Patron
Tera Patron

@chandan2212 Tried running your script in background scripts and it runs just fine. Any specific issues you are facing with this script?