- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2022 11:47 PM
Hello Guys,
We have a variable "SVO" ( Which is select box variable with None) and the we have added below script to add options dynamically based on the value from the other field , The problem here is we need to manually add the options "--None--" in the script to avoid the auto selection of the first option , We have also written a UI Policy to make the field mandatory as below
Onchange client script to dynamically set the Options for SVO field
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var oppr = g_form.getValue('opportunity_id');
var ga = new GlideAjax('QuoteDisplay');
ga.addParam('sysparm_name', 'getQuotedetails');
ga.addParam('sysparm_oppr', oppr);
ga.getXML(populateDetails);
function populateDetails(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var answerArray= answer.split(',');
g_form.clearOptions('svo');
g_form.addOption('svo','--None--','--None--');
//g_form.setMandatory('svo');
for(var i=0; i<answerArray.length; i++){
//g_form.addInfoMessage(answerArray[i]);
// g_form.clearOptions('quote_test');
g_form.addOption('svo',answerArray[i],answerArray[i]); // set this field dynamically based on Opportunity ID variable
}
}
}
Please anyone help me how i can make the field mandatory even if its "--None--"
Solved! Go to Solution.
- Labels:
-
User Interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2022 03:14 AM
Hi,
try to add this line after you clear
g_form.addOption('svo',' ','--None--'); // value is empty for None
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2022 01:17 AM
Do you have any suggestions for this?
Regards,
Bhavna
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2022 01:43 AM
Hi,
when is UI policy running?
why not keep the Include None option on variable?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2022 02:00 AM
I have kept both on variable as well as on the script, The reason is below
1) Initially when the form is loaded the choices on the variable should only be "None"
2) The options should dynamically appear based on the value of the another variable "Opportunity ID" and for that i have written above Onchange client script to Populate the values dynamically, if we do not add "--None--" from the script then it will pick the first available option and set that option as default instead on "--None--" whenever the "Opportunity Id" changes on the form
when is UI policy running? - This UI policy is written on the variable set level( This variable is created inside that variable set) and it has no condition, it simply sets the mandatory fields for that particular varible set
let me know if u need more info
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2022 02:20 AM
Hi,
you want user to select the option right?
if yes then why to add new None option
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader