- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2019 03:59 PM
Hello,
I have a multi line text box variable called all_subprofiles. It is a string of a bunch of users names and their profile. Example:
John Smith - Traditional User
Jane Doe - Special User
Bob Williams - Heavy Traveler
I want to find u_requested_for in the list and then print just their profile. For example, if John Smith is the requestor I just want to print Traditional User.
I tried this but it is just taking off the first three letters instead of taking off the name + ' - '
var name = current.u_requested_for.name;
var currentsub_profile = all_subprofiles.substring(all_subprofiles.indexOf(name)+3);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2019 05:35 PM
Hi Hannah,
A simple way would be to split the string into an array at the comma, for example: currentsub_profile = 'Traditional User, Jane Doe - Special User, Bob Williams - Heavy Traveler', something like this would work:
var string = currentsub_profile.split(',')[0]; //this returns "Traditional User"
You can also achieve this by using regular expression:
var regex = /([^,]+)/;
var string = currentsub_profile.match(regex)[1]; //returns "Traditional User"
Phuong
If you find my suggestions helpful, please mark it as correct or helpful to help out others as well 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2019 04:46 PM
Hi Hannah,
indexOf() returns the first occurrence of the specified value, so for example, if name = 'John Smith', all_subprofiles.indexOf(name) will return 0, then +3 = 3. So you are now effectively taking of the first 3 letter of the whole string: 0 (J), 1(o), 2(h). I hope that makes sense.
Phuong
If you find my suggestions helpful, please mark it as correct or helpful to help out others as well 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2019 04:53 PM
Thank you! I actually figured out how to find the name in the list and then remove the name and the three characters " - " from the front of the string and it is working. But now how to I return everything after the comma in the string?
Here is my code
var name = current.u_approve_it_profile_for.name.toString();
var name_length = name.length;
var currentsub_profile = subprofiles_array.substring(all_subprofiles.indexOf(name) + name_length + 3);
And if the user is John Smith it is returning:
Traditional User, Jane Doe - Special User, Bob Williams - Heavy Traveler
So I need to now remove everything after the first comma...would you be able to help me with that?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2019 05:35 PM
Hi Hannah,
A simple way would be to split the string into an array at the comma, for example: currentsub_profile = 'Traditional User, Jane Doe - Special User, Bob Williams - Heavy Traveler', something like this would work:
var string = currentsub_profile.split(',')[0]; //this returns "Traditional User"
You can also achieve this by using regular expression:
var regex = /([^,]+)/;
var string = currentsub_profile.match(regex)[1]; //returns "Traditional User"
Phuong
If you find my suggestions helpful, please mark it as correct or helpful to help out others as well 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2019 06:41 PM