- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2019 11:45 AM
I have a script that take a value from a text variable, and splits it into an array. It works fine..except, I want the firat array to go into the first text variable, and any subsequent arrays to go into a second text variable.
So, if I get the value from VarA, I want to split it, and push it to VarB and VarC
If the user enters AAA BBB CCC DDD EEE in VarA
VarB shows AAA
VarC shows BBB CCC DDD because I don't have enough arrays defined.
------------------------------------------------------------------------------------------------
If the user enters AAA BBB in VarA
VarB shows AAA
VarC shows BBB undefined undefined because I only have two arrays - anything extra is undefined
What I would like to see is:
VarA = AAA
VarB = anything that come after the first split, no matter how many subsequent splits there are.
------------------------------------------------------------------------------------------------
Many thanks for all replies.....Mark S.
Script is:
function onChange(control, oldValue, newValue, isLoading) { if (isLoading || newValue == '') { return; } var full_name = g_form.getValue('VarA'); var array = full_name.split(" "); var firstname1 = array[0]; var lastname2 = array[1]; var lastname3 = array[2]; var lastname4 = array[3]; g_form.setValue('VarB', array[0]); g_form.setValue('VarC', lastname2 + " " + lastname3 + " " + lastname4); } |
Solved! Go to Solution.
- Labels:
-
Request Management
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2019 01:44 PM
This works just fine now. Many, many thanks!! This is the finished script:
function onChange(control, oldValue, newValue, isLoading) { if (isLoading || newValue == '') { return; } var full_name = g_form.getValue('account_display_name'); var array = full_name.split(" "); var firstname1 = array[0]; var x=''; for(var i=1;i<firstname1.length;i++) { x=x+' '+array[i]; } g_form.setValue('u_first_name', array[0]); g_form.setValue('u_last_name', full_name.split(array[0])[1].trim()); g_form.setReadOnly('u_first_name', true); g_form.setReadOnly('u_last_name', true); } |
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2019 01:18 PM
Hi Ravinder, they all have a max of 63 chars. I tested also by removing this attribute. Cheers, Mark
max_length=63
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2019 02:16 PM
Hi abhinay,
That is an awesome little piece of code! Should be really efficient to run too.
Brent

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2019 02:17 PM
Thanks mate! Glad it helped you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2019 01:26 PM
Did you try the code I provided?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2019 01:28 PM
I am just about too...thanks...