- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2019 08:49 AM
I have a requirement where I need to generate a URL in a field based on sys_ids(values) selected in List Collector
Scenario:
1. When ever I select a value in List Collector from LEFT to RIGHT
2. URL must generate automatically based on the selection of right value
3. All the values in this list collector are from a custom table ('Cust Table')
4. So when ever I select a value from in list collector there is a field allocated for URL. It has to populate dynamically in that URL
5. If I select 1 value URL must contain that sys_id value. If I select 3 values in list collector then I want to have those 3 sys_id's in that URL .
** Based on the number of values i select this URL must take the selected value's sys_id's and add to the url automatically (dynamic)
Example:
Scenario 1
Scenario 2
Solved! Go to Solution.
- Labels:
-
Team Development
-
User Interface (UI)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2019 09:59 AM
Here is the script that works for both back-end view as well as service portal
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var arr = newValue.split(',');
var str = '';
if(arr.length == 1)
str = newValue;
else{
str = arr[0];
for(var i =1; i<arr.length; i++){
str += 'ORparent%3D'+arr[i];
}
}
var url = 'https://'+ top.location.host + '/cust_table.do?sysparm_query=parent%3D' + str;
g_form.setValue('YOUR_variable', url);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2019 09:48 AM
Hello,
You can write an onChange script on your List collector variable and use the following script in it.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}else if(oldValue != newValue){
var url = getInstanceURL();
var ids = newValue.split(",");
for(var i =0;i<ids.length;i++){
var query = "parent="+ids[i].toString();
url += query + "OR";
}
url = url.substring(0, url.length-2);
alert(url);
g_form.setValue('url_variable_name', url); //Replace URL variable name
}
function getInstanceURL(){
var tableName = "cust_table.do?"; //Replace your table name here
var query = "sysparm_query=";
var location = window.location.href;
var url = location.indexOf(".com/");
if(url > -1){
url = location.substring(0,url+5);
url = url+tableName+query;
return url;
}
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2019 09:59 AM
Here is the script that works for both back-end view as well as service portal
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var arr = newValue.split(',');
var str = '';
if(arr.length == 1)
str = newValue;
else{
str = arr[0];
for(var i =1; i<arr.length; i++){
str += 'ORparent%3D'+arr[i];
}
}
var url = 'https://'+ top.location.host + '/cust_table.do?sysparm_query=parent%3D' + str;
g_form.setValue('YOUR_variable', url);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2019 12:29 PM
It worked . 🙂
Thanks DVP