If variable is not empty for catalog item, give an alert

Ankita Gupte
Kilo Sage

Hello Experts,

 

I want to generate alert when Closed complete/Closed incomplete/Closed Skipped UI actions are clicked for closure of catalog task for IT assistance catalog item.

 

Can you please guide what will be the code I have to use in UI action. Or is there any other to do it.

 

It should provide alert when IT assistance for variable is not empty and user is clicking on Closed complete/Closed incomplete/Closed Skipped UI actions.

 

This is my code but its not working

 

if (item_name == 'IT Assistance') {
var sctask_short_description = g_form.getValue('short_description');
// alert('short desc : '+sc_task_short_description);
if ((sctask_short_description == 'Remote Assistance' || sctask_short_description == 'Local Assistance') && (opened_time >= '2022-09-01 00:00:00')) {
var IT_Assistance_for = g_form.getValue('var_it_assistance_for');

if (IT_Assistance_for == "") {
alert("Following fields are mandatory while closing the task- " + "\n" + "Enter the exact requirement briefly, the following are the examples. Meeting room assistance, Meeting room service availability check, Office 365 audit logs, Active directory report, Employee details update in Active directory");
return false;
} else {
g_form.setValue('state', 3);
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'close_sc_task');
}
} else if ((gr.addEncodedQuery('IT_Assistance_forISNOTEMPTY'))) {
alert("You are trying to close the request which is created using IT Assistance catalog item. As per the process, tickets should not be closed using this catalog item when there is a correct catalog item available for this requirement. Therefore, before closing the ticket, please ensure correct catalog item is not available for this requirement, otherwise, closure of this ticket will be considered as non-compliance to the process");
return false;
} else {
g_form.setValue('state', 3);
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'close_sc_task');
}
} else {
g_form.setValue('state', 3);
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'close_sc_task');
}

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

item_name, opened_time, and gr looked to be undefined in your script.  You should do this in a onSubmit Catalog Client Script that Applies on Catalog Tasks.  It would be something more like this:

var sctask_short_description = g_form.getValue('short_description');
// alert('short desc : '+sc_task_short_description);
if ((sctask_short_description == 'Remote Assistance' || sctask_short_description == 'Local Assistance') && (g_form.getValue(opened_at) >= '2022-09-01 00:00:00')) {
    var IT_Assistance_for = g_form.getValue('var_it_assistance_for');
    if (IT_Assistance_for == "") {
        alert("Following fields are mandatory while closing the task- " + "\n" + "Enter the exact requirement briefly, the following are the examples. Meeting room assistance, Meeting room service availability check, Office 365 audit logs, Active directory report, Employee details update in Active directory");
        return false;
    } else {
        g_form.setValue('state', 3);
    }
}

 

View solution in original post

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

item_name, opened_time, and gr looked to be undefined in your script.  You should do this in a onSubmit Catalog Client Script that Applies on Catalog Tasks.  It would be something more like this:

var sctask_short_description = g_form.getValue('short_description');
// alert('short desc : '+sc_task_short_description);
if ((sctask_short_description == 'Remote Assistance' || sctask_short_description == 'Local Assistance') && (g_form.getValue(opened_at) >= '2022-09-01 00:00:00')) {
    var IT_Assistance_for = g_form.getValue('var_it_assistance_for');
    if (IT_Assistance_for == "") {
        alert("Following fields are mandatory while closing the task- " + "\n" + "Enter the exact requirement briefly, the following are the examples. Meeting room assistance, Meeting room service availability check, Office 365 audit logs, Active directory report, Employee details update in Active directory");
        return false;
    } else {
        g_form.setValue('state', 3);
    }
}

 

Hello Brad,

 

Thank you for inputs.

 

But I want this alert when IT Assistance requested for is not empty and when clicked in "Close Complete" UI action.

 

As per above script its executing for all UI action like Save, update since we are doing onsubmit client script also when variable is empty.