UI Action button is not working

Rajendar3
Tera Contributor

I have a UI action called "TEST project" on the demand table. When I click this button, it should create a project. However, my requirement is that, before creating the project, it should validate whether a Resource plan is attached to the current record. If a Resource plan is attached, it should allow the creation of a project. If not, it should display an error message and redirect to the current page. I tried by adding this code in UI action but not working for me

 

UI Action script:

var gDialog;

function convertDemandToProject() {
    var rs = new GlideRecord("resource_plan");
     rs.addQuery('task', current.sys_id);
    rs.query();
    if (rs.next()) {
        gs.addErrorMessage("Record is present");
}
else{
 action.setRedirectURL(current);
}
       

   
    if (g_form.modified) {
        return g_form.addErrorMessage(getMessage('You have not saved all your changes, save the demand record before creating project'));
    }
    if (g_form.getValue('type') == 'project' && g_form.getElement("calculation_type") && !g_form.getValue('calculation_type')) {
        return g_form.addErrorMessage(getMessage('Please select a project calculation type under preferences.'));
    }

    var ga = new GlideAjax("AjaxCreateRelatedEntityFromDemand");
    ga.addParam("sysparm_name""checkPmoUpgrade");
    ga.addParam("sysparm_source_table", g_form.getTableName());
    ga.getXML(function(response) {
        var result = response.responseXML.getElementsByTagName("result");
        var isUpdrading = result[0].getAttribute("isUpgrading");
        var isProjectCurrencyEnabled = result[0].getAttribute("isProjectCurrencyEnabled");
        var isMoreThanOneProjectClassExists = result[0].getAttribute("isMultipleProjectClassExists");
        var defaultProjectTable = result[0].getAttribute("defaultProjectTable");
        if (isUpdrading === "true") {
            g_form.addErrorMessage(getMessage("Financial Planning Upgrade Job Running. Cannot create Project."));
        } else if (isProjectCurrencyEnabled == "true" || isMoreThanOneProjectClassExists == "true") {
            gDialog = new GlideModal('demand_to_project');
            gDialog.setPreference('sysparm_task_id', g_form.getUniqueValue());
            gDialog.setPreference('sysparm_projTable', defaultProjectTable);
            gDialog.setPreference('sysparm_isProjectCurrencyEnabled', isProjectCurrencyEnabled);
            gDialog.setPreference('sysparm_isMoreThanOneProjectTableExists', isMoreThanOneProjectClassExists);
            gDialog.setPreference('on_submit', onSubmit);
            gDialog.setPreference('on_cancel', onCancel);
            gDialog.setTitle(new GwtMessage().getMessage('Create project'));
            gDialog.render();
        } else
            onSubmit(defaultProjectTable);
    });
}
if (typeof window == 'undefined')
    redirect();

function redirect() {

    action.setRedirectURL(current);
}

function onCancel() {
    if (gDialog)
        gDialog.destroy();
    return false;
}

function onSubmit(projName) {
    var createProjectAjax = new GlideAjax("AjaxCreateRelatedEntityFromDemand");
    createProjectAjax.addParam("sysparm_name""createProjectAjax");
    createProjectAjax.addParam("sysparm_sys_id", g_form.getUniqueValue());
    createProjectAjax.addParam("sysparm_projName", projName);
    createProjectAjax.getXML();

    if (gDialog)
        gDialog.destroy();
    g_form.save();

    return false;
    
}
 

Rajendar3_0-1694519728319.pngRajendar3_1-1694519780906.png

 

0 REPLIES 0