How to add Drop down in string field for perticular condition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 09:57 PM
Hi Community,
Urgent Help Require:
I need to add drop down to the string field and that drop down should be visible only for the model category computer in hardware table.
Thanks,
Manu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 10:06 PM
Hi @Manu143
Let's try this API in your client script. You will be able to add choice value in a specific condition.
addOption(String fieldName, String choiceValue, String choiceLabel)
To make a string field act as dropdown list. You'll need to update the Choice List Specification in Dictionary.
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 11:51 PM
Hi Tai Vu,
I tried that as well but if I will go with that approach the dropdown will be visible to other model category as well.That field will get change for everywhere and I just want that only for model category computer.
Thanks,
Manu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 12:01 AM
Hi,
You need to use addOption() along with removeOption() to get it worked as per your use case.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 12:09 AM - edited 11-07-2023 12:11 AM
Hi @Manu143
We can validate the Hardware Model Category before calling the API.
Sample below.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
if (newValue === '') {
g_form.removeOption('<field_name>', '<choice_value>');
return;
}
if (g_form.getValue('model_category') === '81feb9c137101000deeabfc8bcbe5dc4') {
g_form.addOption('<field_name>', '<choice_value>', '<choice_label>');
return;
}
g_form.removeOption('<field_name>', '<choice_value>');
}
If you'd like the script runs on load, just remove the isLoading condition.
If you don't want to hard-coding the sys_id of the Computer category, you can store it in a system property then call an AJAX to do the validation.
Cheers,
Tai Vu
