- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2022 11:12 PM
Based on user location catalog variable option will change. have got location from script include but after that if else condition is not working properly. Any one condition works properly. Below is my script. Please help me with this
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2022 01:38 PM
In add option, try putting quotes around 1 and 2... such as '1' and '2'.
Reference: https://developer.servicenow.com/dev.do#!/reference/api/quebec/client/c_GlideFormAPI#r_GlideformAddOption_String_String_String
addOption(String fieldName, String choiceValue, String choiceLabel)
Name | Type | Description |
---|---|---|
fieldName | String | The name of the field. |
choiceValue | String | The value to be stored in the database. |
choiceLabel | String | The value displayed. |
OR
addOption(String fieldName, String choiceValue, String choiceLabel, Number choiceIndex)
Name | Type | Description |
---|---|---|
fieldName | String | The field name. |
choiceValue | String | The value stored in the database. |
choiceLabel | String | The value displayed. |
choiceIndex | Number | Order of the choice in the list. The index is into a zero based array. |
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2022 05:01 AM
Hi Bhuvi,
Can you please share your desired output for each country?
and also the default backed option already added to list.
Regards,
Rahul
Thanks and Regards,
Rahul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2022 10:33 AM
Hi Rahul,
These are the 3 options and conditions needs to apply on "i want to" variable based on Requester for (user's location).
- Display “Generate statement” to Bahrain user.
- Display “Reprint statement” & “Reprint report” to Indonesia
- Display “Reprint statement” to Malaysia user.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2022 01:38 PM
In add option, try putting quotes around 1 and 2... such as '1' and '2'.
Reference: https://developer.servicenow.com/dev.do#!/reference/api/quebec/client/c_GlideFormAPI#r_GlideformAddOption_String_String_String
addOption(String fieldName, String choiceValue, String choiceLabel)
Name | Type | Description |
---|---|---|
fieldName | String | The name of the field. |
choiceValue | String | The value to be stored in the database. |
choiceLabel | String | The value displayed. |
OR
addOption(String fieldName, String choiceValue, String choiceLabel, Number choiceIndex)
Name | Type | Description |
---|---|---|
fieldName | String | The field name. |
choiceValue | String | The value stored in the database. |
choiceLabel | String | The value displayed. |
choiceIndex | Number | Order of the choice in the list. The index is into a zero based array. |

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2022 05:16 PM
Hi Bhuvi,
I've changed so the value of the selection will be "generate_statement", "reprint_statement", "reprint_report".
Argument to pass to .removeOption() is the value of the option. So, it the value is set to 1, then 1 should be passed.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var user = new GlideAjax('GetUserLocationDetails');
user.addParam('sysparm_name', 'getuserlocation');
user.addParam('sysparam_user', newValue);
user.getXML(getRequireddata);
function getRequireddata(response) {
var answer = response.response.documentElement.getAttribute('answer');
if (answer == 'Bahrain') {
g_form.addOption('i_want_to', 'generate_statement', 'Generate statement');
g_form.removeOption('i_want_to', 'reprint_statement');
g_form.removeOption('i_want_to', 'reprint_report');
} else if (answer == 'Indonesia') {
g_form.addOption('i_want_to', 'reprint_statement', 'Reprint Statement');
g_form.addOption('i_want_to', 'reprint_report', 'Reprint Report');
g_form.removeOption('i_want_to', 'generate_statement');
} else if (answer == 'Malaysia') {
g_form.addOption('i_want_to', 'reprint_statement', 'Reprint statement');
g_form.removeOption('i_want_to', 'generate_statement');
g_form.removeOption('i_want_to', 'reprint_report');
}
}
}