Write a business rule to trim string field value

AnilM99
Tera Expert

Hi Team,

I have requirement to write a business rule - It should trim a String field value

example: "TEMP\anil

Answer should be "anil"

 

Please help me on the same

1 ACCEPTED SOLUTION

Omkar Mone
Mega Sage

Hello Anil,

 

You should try the below code - 

 

var st = "TEMP\anil";
var stnew = st.split(/[.\-=/_]/)[0]; //will remove the backslash character and any special character.
gs.info(stnew.toString().split("TEMP")[1]); // will give you your output as desired

 

Let me know if it helped.

 

Regards,

Omkar

View solution in original post

3 REPLIES 3

Musab Rasheed
Tera Sage
Tera Sage

Hello,

Below thread has working code, Mark my answer as correct if that helps

https://community.servicenow.com/community?id=community_question&sys_id=a8afb62ddb58dbc01dcaf3231f9619dc

Regards

Please hit like and mark my response as correct if that helps
Regards,
Musab

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use RegEx and remove the value

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Omkar Mone
Mega Sage

Hello Anil,

 

You should try the below code - 

 

var st = "TEMP\anil";
var stnew = st.split(/[.\-=/_]/)[0]; //will remove the backslash character and any special character.
gs.info(stnew.toString().split("TEMP")[1]); // will give you your output as desired

 

Let me know if it helped.

 

Regards,

Omkar