- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2017 11:46 AM
Hello experts,
I'm new to coding, and trying to accomplish a task, not sure how this can be done.
I have this If/else statement that i'm checking to see set choice list for the variable, which works as intended. However, I want to set choices depending on which is true. If 'answer = 2 then default type to 'Add User' else default 'type' to 'Request info'. Can this be possible within this If/else condition?
if (answer == 2) {
g_form.addOption('type', 'Add User', 'Add User');
g_form.addOption('type', 'Edit User', 'Edit User');
} else {
g_form.addOption('type', 'Request Info', 'Request Info');
g_form.addOption('type', 'Request Access', 'Request Access');
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
-
Team Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2017 12:14 PM
Thanks for the details Kim. Here is the updated code.
if (answer == 2) {
g_form.addOption('type', 'Add User', 'Add User');
g_form.addOption('type', 'Edit User', 'Edit User');
g_form.setValue('type', 'Add User');
} else {
g_form.addOption('type', 'Request Info', 'Request Info');
g_form.addOption('type', 'Request Access', 'Request Access');
g_form.setValue('type', 'Request Info');
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2017 12:02 PM
Hello Kim,
Here is the updated code.
if (answer == 2) {
g_form.setValue('type', 'Add User');
} else {
g_form.setValue('type', 'Request Info');
}
Please let me know if you have any questions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2017 12:08 PM
Hi Pradeep,
Thanks for your reply. But this is not what I'm trying to do. I have to display the 2 choices if answer = 2 regardless. The idea is to not show all 4 choices within the choice list. But instead of showing '--None--', I want it to default to the 'Add User' ELSE 'Request Info'.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2017 12:14 PM
Thanks for the details Kim. Here is the updated code.
if (answer == 2) {
g_form.addOption('type', 'Add User', 'Add User');
g_form.addOption('type', 'Edit User', 'Edit User');
g_form.setValue('type', 'Add User');
} else {
g_form.addOption('type', 'Request Info', 'Request Info');
g_form.addOption('type', 'Request Access', 'Request Access');
g_form.setValue('type', 'Request Info');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2017 12:22 PM
Hi Pradeep,
That works as intended. But now I'm seeing another problem. My UI Policy I have on that 'Add User' to show other variables when 'type' = 'Add User' does not execute. My guess is because of 2 rules running at the same time, and this onChange client script takes precedence?