Extract characters from a string in transform map

deodis
Mega Contributor

Hello Community!

A LDAP inteface is running on our instance. From the source table, the value of the field "Manager" is sent as :   cn=313314,CN=3ce5f7a2,OU=IAMIDENTITY,dc=

1 - What I need, is for the transform map to only catch the characters between 'cn=' and ' ,CN= ', so for this example, I want the target field "Manager" to have the value of 313314

2 - This value refers to users ID, however the "manager" field on the sys_user table (which is my target table) associates a user with first and last name. So I need the transform map to extract the user ID, and set the First and last name value unto the "Manager" field in the sys_user table.

I can't seem to have a right script to do so.

Thank you very much for your help!

1 ACCEPTED SOLUTION

ark6
Mega Guru

Try this on an onBefore transform script



var a=source.u_manager;


var b=a.split(',');


for(var i=0;i<b.length;i++)


{


var c=b[i];


var d=c.split('=');


var manager =d[1];//this will contain the manager employee id


var gr=new GlideRecord('sys_user');


gr.addQuery('user_name',manager);


gr.query();


if(gr.next())


{


target.manager=gr.sys_id;


}



}}



This script will work . Please try it and let me know if it worked.


View solution in original post

2 REPLIES 2

ark6
Mega Guru

Try this on an onBefore transform script



var a=source.u_manager;


var b=a.split(',');


for(var i=0;i<b.length;i++)


{


var c=b[i];


var d=c.split('=');


var manager =d[1];//this will contain the manager employee id


var gr=new GlideRecord('sys_user');


gr.addQuery('user_name',manager);


gr.query();


if(gr.next())


{


target.manager=gr.sys_id;


}



}}



This script will work . Please try it and let me know if it worked.


deodis
Mega Contributor

Hi Arka!



It did work. it's perfect! Thank you VERY MUCH