- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2017 08:59 PM
Hello,
I currently have a requirement that on the click of a Request Approval UI Action, certain fields need to be made mandatory. At first, only 4 fields needed to be a part of this, however the requirements changed and 5 additional fields were added to the list. The first 4 fields are working properly, if the field doesn't contain a value, an error message appears and the red asterisk appears next to the appropriate field.
I added the 5 additional fields into the UI Action, navigated back to the form, and clicked it. This time, the first 4 fields were identified with a red asterisk, but the 5 additional fields that I added did NOT have the red asterisk next to them. I tested another field in the same form section and the red asterisk appeared. I then created a new 'test' field and included it in the UI Action script, but no asterisk. I've included my code below:
function requestApproval() {
var quantities = g_form.getValue('quantities');
var pricingStructure = g_form.getValue('pricing_structure');
var pricing = g_form.getValue('pricing');
var freight = g_form.getValue('freight');
var stc = g_form.getValue('u_standard_terms_and_conditions');
var perUnitCost = g_form.getValue('u_specified_per_unit_cost');
var minPurchase = g_form.getValue('u_minimum_purchase_requirement');
var initialPayment = g_form.getValue('u_initial_payment_to_enter_agreement');
var penalties = g_form.getValue('u_specified_penalties_for_breaking');
if((quantities == '') || (pricingStructure == '') || (pricing == '') || (freight == '') || (stc == '') || (perUnitCost == '') || (minPurchase == '') || (initialPayment == '') || (penalties == '')) {
g_form.setMandatory('quantities', true); //Red asterisk appears for this field
g_form.setMandatory('pricing_structure', true); //Red asterisk appears for this field
g_form.setMandatory('pricing', true); //Red asterisk appears for this field
g_form.setMandatory('freight', true); //Red asterisk appears for this field
g_form.setMandatory('stc', true); /*Red asterisk DOES NOT appear*/
g_form.setMandatory('perUnitCost', true); /*Red asterisk DOES NOT appear*/
g_form.setMandatory('minPurchase', true); /*Red asterisk DOES NOT appear*/
g_form.setMandatory('initialPayment', true); /*Red asterisk DOES NOT appear*/
g_form.setMandatory('penalties', true); /*Red asterisk DOES NOT appear*/
g_form.addErrorMessage('You must complete all mandatory fields before requesting approval.');
return false;
}
// Call the UI Action, and skip the "onclick" function.
gsftSubmit(null, g_form.getFormElement(), 'request_approval');
}
if (typeof window == 'undefined')
validateRequest();
function validateRequest() {
current.status = 'approval_requested';
current.update();
action.setRedirectURL(current);
}
I think it might be an issue with ServiceNow, but I wanted to see if anyone else has ever had this issue or knows of a way to resolve it. Thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2017 10:31 AM
**UPDATE**
I figured out my issue. If you look at the code, you'll notice that I used the variables (which were the values of the fields) instead of using the field name in my setMandatory(). I was using g_form.setMandatory('stc', true); instead of g_form.setMandatory('u_standard_terms_and_conditions', true);
Thank you for responding Gurpreet!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2017 09:26 PM
Any errors on console? Any other conflicting UI Policies/Scripts ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2017 09:14 AM
Hello Gupreet,
I can't find any errors on the console nor are there any conflicting UI policies or scripts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2017 10:10 AM
Gurpreet,
For the JS log (referencing code from my original question):
g_form.setMandatory('freight', true); //Red asterisk appears for this field
jslog(g_form.isMandatory('freight')); *Returns True
g_form.setMandatory('stc', true); /*Red asterisk DOES NOT appear*/
jslog(g_form.isMandatory('freight')); *Returns False
The jslog is saying that the fields are not mandatory even though I am unable to save the record unless I complete all of those fields.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2017 10:31 AM
**UPDATE**
I figured out my issue. If you look at the code, you'll notice that I used the variables (which were the values of the fields) instead of using the field name in my setMandatory(). I was using g_form.setMandatory('stc', true); instead of g_form.setMandatory('u_standard_terms_and_conditions', true);
Thank you for responding Gurpreet!