- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2020 07:31 AM
Hi,
Could you please help me on below issue.
How to split CN = value only and store in array variable
CN=COBROUTEV2,OU=Servers,OU=Computers,OU=COB,DC=abc,DC=root^CN=BTHORMANVM1,OU=Workstations,DC=abc,DC=root
i tried below one but not working.
var gr=current.u_member.split(',');
var gg=gr.split('CN=');
gs.addInfoMessage(gs.getMessage("GR:"+gg));
it is returning single CN= value, but there are 2 CN values.
some records had 10 CN values. so how can we do this time.
How to fix this issue.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2020 11:19 AM
Try below.
var getinarray=[];
var textis='CN=COBROUTEV2,OU=Servers,OU=Computers,OU=COB,DC=abc,DC=root^CN=BTHORMANVM1,OU=Workstations,DC=abc,DC=root';
textis=textis.replace(/\^/g,','); //replaces ^ with comma
var splitcomma=textis.split(','); //splits by comma
for(var i=0;i<splitcomma.length;i++)
{
if(splitcomma[i].indexOf('CN=')>-1) //if contains CN it will go in if loop
{
getinarray.push(splitcomma[i].split('=')[1]);
}
}
gs.print('Value is '+getinarray);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2020 10:58 AM
Hi Jaspal,
Thanks for reply,
it is working great, can we show only BTHORMANVM1 , COBROUTEV2 and push these two values into array?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2020 11:19 AM
Try below.
var getinarray=[];
var textis='CN=COBROUTEV2,OU=Servers,OU=Computers,OU=COB,DC=abc,DC=root^CN=BTHORMANVM1,OU=Workstations,DC=abc,DC=root';
textis=textis.replace(/\^/g,','); //replaces ^ with comma
var splitcomma=textis.split(','); //splits by comma
for(var i=0;i<splitcomma.length;i++)
{
if(splitcomma[i].indexOf('CN=')>-1) //if contains CN it will go in if loop
{
getinarray.push(splitcomma[i].split('=')[1]);
}
}
gs.print('Value is '+getinarray);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2020 11:29 AM
Thanks Jaspal, Thanks a lot. thanks for your answer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2020 11:13 AM
when i used below script it is showing "," additionally so how to remove that.
var arr = [];
var textis = current.u_member.toString();
textis = textis.replace(/\^/g, ','); //replaces ^ with comma
var splitcomma = textis.split(','); //splits by comma
for (var i = 0; i < splitcomma.length; i++) {
if (splitcomma[i].indexOf('CN=') > -1) //if contains CN it will go in if loop
{
gs.print('Value is ' + splitcomma[i]);
gs.addInfoMessage(gs.getMessage(splitcomma[i]));
var spl = splitcomma[i].split("CN=");
gs.addInfoMessage(gs.getMessage(spl));
arr.push(spl);
}
}
for (var j = 0; j < arr.length; j++) {
gs.addInfoMessage(gs.getMessage("ARRAY VALUES " + arr[j]));
}
