UI Action Client Script assistance please

Annette Kitzmil
Tera Guru

Hello,

I have added this code to an existing UI Action client script because I need to ensure that when the user selects a Type of Correction Requested that is added after the initial submission, that those fields will be required.  To further clarify, if the user initially selected the Term for the account when submitting the case and then needs to go back and add another type of correction requested like backdating, there is another field that displays dynamically that the user has to fill in before clicking the Resubmit button.  My script below is requiring the user to complete all of the fields even though they were not added to the form.  I should only be validating fields that are on the form to ensure they are filled in.  I know it is probably something stupid, but I would appreciate some assistance please?

 

This needed to be added to the UI Action client script because it also goes onto display a modal that the user completes before the resubmit can be completed.  Doing it any other way doesn't ensure the fields are completed.

 

function onClick(g_form) {

    var reqTermForAcctEmpty = g_form.getValue('exception_for_term_account') === '';
    var reqBackDatingEmpty = g_form.getValue('exact_date_for_backdating') === '';
    var reqInterestRateEmpty = g_form.getValue('requested_interest_rate_for_account') === '';
    var reqApyOrAprEmpty = g_form.getValue('is_this_rate_an_apy_or_apr') === '';

    var missingFields = [];

    if (reqApyOrAprEmpty || reqBackDatingEmpty || reqInterestRateEmpty || reqTermForAcctEmpty) {
        if (reqApyOrAprEmpty) {
            missingFields.push('Is this rate an APY or APR?');
        }
        if (reqBackDatingEmpty) {
            missingFields.push('Exact date for backdating');
        }
        if (reqInterestRateEmpty) {
            missingFields.push('Requested interest rate for account');
        }
        if (reqTermForAcctEmpty) {
            missingFields.push('Requested Term for Account');
        }
        g_form.addErrorMessage('The following mandatory fields are not filled in: ' + missingFields);
        return;
    }
 
Thanks,
Annette
5 REPLIES 5

You need to convert your missingFields variable to a string. When you display your error message, change those lines to this: 

g_form.addErrorMessage('The following mandatory fields are not filled in: ' + missingFields.join(', '));