- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2022 04:56 AM
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2022 05:33 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2022 05:20 AM
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
Regards,
Musab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2022 05:27 AM
Hi,
you can use RegEx and remove the value
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2022 05:33 AM
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