How to retrieve words from a string field?

SN_Learn
Kilo Patron
Kilo Patron

Hi All,

 

I have some strings stored in a field on an Incident form.

 

example:

field_name = description

It contains the highlighted string: No-conflict,P3-Priority,Chief Testing,xt_mapping:FURIOUS,XTREM, gt_kick:rtr,xt_mention:CC-Dnr-pola,[Google]type_believe:customer,xt_mention:hpi-t9d-brmr,[google]xt_mapping:GROUP


My requirement is to get the data which is stored in xt_mapping and xt_mention fieldsIt means I wish to get all the data which is stored in both those field in the whole string.

The output should contain FURIOUS and  GROUP
For, xt_mention the output should be CC-Dnr-pola and pi-t9d-brmr

 

Any help would be appreciated, thanks.

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.
1 ACCEPTED SOLUTION

The below code worked fine, thank you for the assistance.
 
 
var a = 'No-conflict,P3-Priority,Chief Testing,xt_mapping:FURIOUS,XTREM, gt_kick:rtr,xt_mention:CC-Dnr-pola,[Google]type_believe:customer,xt_mention:hpi-t9d-brmr,[google]xt_mapping:GROUP, xt_goodies: Testing';
var b = a.split(',');
var tag = 'xxt_mention:';

for(i = 0; i< b.length; i++){
if(b[i].indexOf('xt_mention') != -1){
var c = b[i].split(':');
tag += c[1] + ',';
}
}
gs.print(tag);
----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

View solution in original post

5 REPLIES 5

Namrata Ghorpad
Mega Sage
Mega Sage

Hello,

For the first output try the below code

var str='No-conflict,P3-Priority,Chief Testing,xt_mapping:FURIOUS,XTREM, gt_kick:rtr,xt_mention:CC-Dnr-pola,[Google]type_believe:customer,xt_mention:hpi-t9d-brmr,[google]xt_mapping:GROUP';
var test=str.split('xt_mapping')[1];
var aa=test.slice(1,8);
gs.print(aa);
var abc=str.split('xt_mapping')[2];
gs.print(abc);

For the second output try below code.

var str='No-conflict,P3-Priority,Chief Testing,xt_mapping:FURIOUS,XTREM, gt_kick:rtr,xt_mention:CC-Dnr-pola,[Google]type_believe:customer,xt_mention:hpi-t9d-brmr,[google]xt_mapping:GROUP';
var test=str.split('xt_mention')[1];
var aa=test.slice(1,12);
gs.print(aa);
var abc=str.split('xt_mention')[2];
var bb=abc.slice(1,13);
gs.print(bb);

 

Please mark my answer as helpful/correct if it helps you.

Regards,

Namrata

Hi Namrata, thanks for the response.

 

In the slice operation, you have mentioned the position of those strings but what if we don't know where they will be placed maybe in some other string it will be in different position. Let us suppose in some other list of string it will occur 3 times and the position has also shifted but we don't want to check the position each and every time, we will define the code in schedule job and it will automatically fetch those values.

 

We need to automate it not provide the position manually and run the code each time. Could you please provide any insight on this situation? Thank you.

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

Hello,

For the first output try the code like below.

var str = 'No-conflict,P3-Priority,Chief Testing,xt_mapping:FURIOUS,XTREM, gt_kick:rtr,xt_mention:CC-Dnr-pola,[Google]type_believe:customer,xt_mention:hpi-t9d-brmr,[google]xt_mapping:GROUP';    
var abc=str.split('xt_mapping:')[1];
var test1=abc.split(',')[0];
gs.print(test1);
var test2=str.split('xt_mapping:')[2];
gs.print(test2);

 

For the second output try the code like below.

var abc1=str.split('xt_mention:')[1];
var t1=abc1.split(',')[0];
gs.print(t1);
var abc2=str.split('xt_mention:')[2];
var t2=abc2.split(',')[0];
gs.print(t2);

 

Please mark my answer as helpful/correct if it helps you.

Regards,

Namrata

Hi Namrata, thanks.

 

But I am still not getting the desired output. For example:

var str = 'No-conflict,P3-Priority,Chief Testing,xt_mapping:FURIOUS,XTREM, gt_kick:rtr,xt_mention:CC-Dnr-pola,[Google]type_believe:customer,xt_mention:hpi-t9d-brmr,[google]xt_mapping:GROUP, xt_goodies: Testing';

I have added one more tag in the end of the above string, if I will run the same it will give me the output: GROUP,xt_goodies: Testing

 

But this desired output is only GROUP. So, it should only provide an output that is in between':'(colon) and ','(comma) which is just after that colon.

 

Could you please assist me with that, thanks.

 

 

 

 

 

 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.