Popup on change request form when user clicks on a ui action and state is in draft or new

Poorva Bhawsar
Mega Sage

Hi Community,

 

I have a custom field created on the change form which is a checkbox field. Until user check that checkbox and there are no related items in the change requests related list, i want to show an alert. Also, when user clicks on request approval ui action and state is new or draft all the time then i want to show same alert. Any one condition satisfies then want to show this alert i.e. either that checkbox is checked or there are no related items in the related list then show alert.

 

var gr = new GlideRecord('change_request');
//gr.addQuery('parent', value);
//gr.addQuery("unable to test in PPT", false);
gr.addEncodedQuery("parent=^ORu_non_production_test_not_required=false");
gr.addQuery("state", -5);
gr.query();
if (!gr.next()) {
    gs.addInfoMessage('A valid non production change must be linked in the "Change Requests" related list or justification for no non-production test evidence provided via the "Non Production Test Not Required" checkbox.');
}
 
This is the script but its not working.
6 REPLIES 6

Amit Gujarathi
Giga Sage
Giga Sage

HI @Poorva Bhawsar ,
I trust you are doing great.
Please find the updated code which you can reference .

function onLoad() {
    // Add the alert functionality when the form is loaded
    showAlert();
}

function showAlert() {
    var nonProdTestNotRequired = g_form.getValue('u_non_production_test_not_required');
    var state = g_form.getValue('state');
    
    // Check if the checkbox is unchecked
    if (nonProdTestNotRequired == 'false' || nonProdTestNotRequired == '') {
        
        // Check if there are no related items in the "Change Requests" related list
        var gr = new GlideRecord('change_request');
        gr.addQuery('parent', g_form.getUniqueValue());
        gr.query();
        
        if (!gr.next()) {
            gs.addInfoMessage('A valid non-production change must be linked in the "Change Requests" related list or justification for no non-production test evidence provided via the "Non Production Test Not Required" checkbox.');
        }
    }
    
    // Check if the "Request Approval" UI action is clicked and the state is "New" or "Draft"
    if (state == '-5' || state == '1') {
        gs.addInfoMessage('A valid non-production change must be linked in the "Change Requests" related list or justification for no non-production test evidence provided via the "Non Production Test Not Required" checkbox.');
    }
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



Is it on ui action? Because we cant use gs in client scripts.

This is not working on ui action. 

Ankur Bawiskar
Tera Patron
Tera Patron

@Poorva Bhawsar 

where have you written the script? what debugging have you done so far?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader