- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2024 11:58 AM - edited 09-05-2024 12:09 PM
Hi,
I have a requirement to populates(add) value in a list collector's value/ remove the value of the list collector field, based on 3 check box fields.
I have tried Script include and onChange client script and also tried to modify through Reference qualifier of the list collector field. But nothing is working.
Please suggest me a better way to achieve it.
Reference picture of my requirement:
- If the user choose Digital Engg app in the Application field, the check boxes will appear.
- Then if user checks any check box, it will add/remove the value in Application field.
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2024 03:46 PM
Good job with the logs. You were very close - just a misplaced } that was causing there to be no 'else' to the if (newValue == 'true'). Then you would have discovered that you want to use splice to remove an element from an array in this case, not slice which creates a new array with the removed elements. Here's the working if block:
if (newValue == 'true') {
if (appVal.indexOf(jira_sysid) === -1) {
appVal.push(jira_sysid);
alert('added: ' + jira_sysid);
}
} else {
var index = appVal.indexOf(jira_sysid);
alert('index found at: ' + index);
if (index != -1) {
alert('removing');
appVal.splice(index, 1);
} else {
alert('value not found for removal!');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2024 12:21 PM
An onChange client script when each checkbox changes is the way to go. Get one nailed down, then copy it to trigger on the other two. All you need to do is set the value of the list collector to a comma-separated list of sys_ids for records on the list table. Post your script attempt if you are still stuck.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2024 02:48 PM - edited 09-06-2024 12:36 AM
Hi @Brad Bowman ,
Thanks for the reply!
I wrote the onChange client script as you said and Adding value to the List collector field is working. But the removing part is not working. It's not entering to the else part (not even getting any alerts from else part).
Pasted my code below. Can you please find my fault.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var getCollector = g_form.getValue('applications');
var jira_sysid = 'ea7b1a23dba4ca5855afd383f39619ea'; //'Jira Cloud'
alert('value: ' + newValue);
alert('app field before: ' + getCollector);
var appVal = getCollector.split(',');
alert('app field current: ' + getCollector);
alert('value to add/remove: ' + newValue);
if (newValue == 'true') {
if (appVal.indexOf(jira_sysid) === -1) {
appVal.push(jira_sysid);
alert('added: ' + jira_sysid);
} else {
var index = appVal.indexOf(jira_sysid);
alert('index found at: ' + index);
if (index !== -1) {
appVal.slice(index, 1);
} else {
alert('value not found for removal!');
}
}
}
var newAppVal = appVal.join(',');
g_form.setValue('applications', newAppVal);
alert('app field after: ' + newAppVal);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2024 03:46 PM
Good job with the logs. You were very close - just a misplaced } that was causing there to be no 'else' to the if (newValue == 'true'). Then you would have discovered that you want to use splice to remove an element from an array in this case, not slice which creates a new array with the removed elements. Here's the working if block:
if (newValue == 'true') {
if (appVal.indexOf(jira_sysid) === -1) {
appVal.push(jira_sysid);
alert('added: ' + jira_sysid);
}
} else {
var index = appVal.indexOf(jira_sysid);
alert('index found at: ' + index);
if (index != -1) {
alert('removing');
appVal.splice(index, 1);
} else {
alert('value not found for removal!');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2024 10:58 PM
Hi, it works. 😊 Thanks @Brad Bowman