The CreatorCon Call for Content is officially open! Get started here.

Make mandatory before complete

Annette Kitzmil
Tera Guru

Hi Everyone,

So, I have three fields that need to be mandatory before the user is able to Complete a case.  I have a UI Policy shown below, but when I click the Complete button, it brings up the modal to have the user enter the comments and allows the user to complete the case without completing the fields shown below.  I have the UI Action code and related AJAX script for the Complete Update button that is showing the modal and allowing the user to close this out even though the UI Policy and the fields on the form show mandatory.  I originally had them set to mandatory on the main table, but this then made the fields mandatory on submission and we only want them mandatory before the user completes the case.  

 

AnnetteKitzmil_0-1724349570282.pngAnnetteKitzmil_1-1724349593352.png

 

Here is the script for the Complete UI Action:

 

function onClick(g_form) {
    g_modal.showFields({
        title: "Enter Completed comments",
        fields: [{
            type: 'textarea',
            name: 'work_notes',
            label: getMessage('Reason'),
            mandatory: false
        }],
        size: 'lg'
    }).then(function(fieldValues) {
        //call AJAX script      
        //alert(fieldValues.updatedFields[0].value);
        var ga = new GlideAjax('x_mtbr_ebs_rdep.RDEPUtilsAJAX');
        ga.addParam('sysparm_name', 'rdepCompleteUpdate');
        //ga.addParam('sysparm_state', 'completed'); // Completed
        ga.addParam('sysparm_comments', fieldValues.updatedFields[0].value);
        //ga.addParam('sysparm_reason', fieldValues.updatedFields[1].value);
        ga.addParam('sysparm_sysid', g_form.getUniqueValue());
        //alert(fieldValues.updatedFields[0].value);
        ga.getXML(reload);
    });
}

function reload() {
    g_form.reload();
}

 

====================================

Here is the AJAX part of the script:

rdepCompleteUpdate: function() {
        //  gs.info('RDEPUtilsAJAX');
        var sysId = this.getParameter('sysparm_sysid');
        //var statusCode = this.getParameter('sysparm_state'); //  
        var comments = this.getParameter('sysparm_comments'); // used for Approval notes
        var grRDEP = new GlideRecord('x_mtbr_ebs_rdep_retail_deposit_exception_pricing');
        var statusCode;

        grRDEP.get('sys_id', sysId);
        statusCode = grRDEP.getValue('status');

        if (statusCode == 'pt_approved' || statusCode == 'confirmed' || statusCode == 'cor_support_approved') {
            grRDEP.status = 'completed';
            grRDEP.active = false;
        }
        gs.info('rdep_status' + statusCode);
        grRDEP.comments = comments;
        grRDEP.update();
    },
 
I appreciate any help in getting this to the place I want.
Thanks 🙂

 

3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

Try changing/converting the UI Policy to a Data Policy - you may need to inactivate the UI Policy and create a new Data Policy...

Hi Brad,

Thanks, I tried that and still got the same results.

AnirudhKumar
Mega Sage

Inside your OnClick(), just before you call the modal you could have 3 if conditions to check for the values on those 3 fields. If one of them is empty, then throw an alert and return false;