Complete triage ui action button changes

harinya
Tera Contributor

Hi ,
Below is my requirement,
on the  issue triage form if source is 'qa_finding' value and Result value is '2'(compliance as new issue) and if user click on complete triage ui action and it needs to check the any open issues are present on the control form( means on the issue triage form there is control field tagged issue which are open)
then ui action button clicks display on alert messgae with ok and cancel button if user click on ok it should display a modal (which is already there) for that need to modify the OOB Complete triage ui action changes
i have tried code in my pdi it is showing display message but when i add script include it will not working
please help on this,
alert messages are showing from script include onwards it is not going
workspace client script:

I have added my condition is from  this // Check related issues for the control

function onClick(g_form) {
    createNewIssue();
}

function createNewIssue() {
    var issueManager = g_form.getValue('issue_manager');
    var issueManagerGroup = g_form.getValue('issue_manager_group');

    // Check if the form has unsaved changes
    if (g_form.serialize(true) != '') {
        g_form.addInfoMessage(getMessage("Please save your changes before completing triage."));
        return false;
    }

    // Validate mandatory fields
    if ((g_form.getValue('recommendation') == '3' || g_form.getValue('recommendation') == '5') && g_form.getValue('confirmed_issue') == '') {
        g_form.addErrorMessage(getMessage("Incomplete mandatory fields: Existing issue."));
        return false;
    }

    if (g_form.getValue('state') == '1' && g_form.getValue('assigned_to') == '') {
        g_form.addErrorMessage(getMessage("Incomplete mandatory fields: Triage owner."));
        return false;
    }

    if (g_form.getValue('state') == '2' && g_form.getValue('reviewer') == '') {
        g_form.addErrorMessage(getMessage("Incomplete mandatory fields: Reviewer."));
        return false;
    }

    if (g_form.getValue('item') != '' && g_form.getValue('risk') != '') {
        g_form.addErrorMessage(getMessage("You have selected both a risk and a control. An issue can be created only for one or the other. Please try again."));
        return false;
    }

    if ((g_form.getValue('recommendation') == '2' || g_form.getValue('recommendation') == '4') && g_form.getValue('issue_manager') == '' && g_form.getValue('issue_manager_group') == '') {
        issueManagerGroup = g_form.getValue('assignment_group');
        issueManager = g_form.getValue('assigned_to');
    }

    if (g_form.getValue('recommendation') == '2') {
        if (g_form.getValue('issue_type') == '2' && g_form.getValue('authority_document') == '') {
            g_form.addErrorMessage(getMessage("Authority document is required."));
            return false;
        } else if ((g_form.getValue('issue_type') == '3' || g_form.getValue('issue_type') == '4') && g_form.getValue('policy') == '') {
            g_form.addErrorMessage(getMessage("Policy is required."));
            return false;
        } else if (g_form.getValue('item') == '' && g_form.getValue('content') == '' && g_form.getValue('profile') == '') {
            g_form.addErrorMessage(getMessage("Either Entity or Control or Control objective is required."));
            return false;
        }
    }

    if (g_form.getValue('recommendation') == '4' && g_form.getValue('risk') == '' && g_form.getValue('risk_statement') == '') {
        g_form.addErrorMessage(getMessage("Either Risk or Risk statement is required."));
        return false;
    }

    // Validate issue due date
    if (g_form.getValue('issue_due_date') != '') {
        var issueDueDate = g_form.getValue('issue_due_date');
        var dates = [];
        dates.push(issueDueDate);
        var ga = new GlideAjax('sn_grc.GRCDateFormatUtilsWS');
        ga.addParam('sysparm_name', 'getNumericValueFromDates');
        ga.addParam('sysparm_dates', JSON.stringify(dates));
        ga.getXMLAnswer(function(answer) {
            if (answer != '') {
                var formattedDates = JSON.parse(answer);
                var now = new Date();
                var issueDueDateObj = new Date(formattedDates[0]);
                if (now.getTime() > issueDueDateObj.getTime()) {
                    g_form.addErrorMessage(getMessage('Issue due date cannot be in the past.'));
                    g_form.hideFieldMsg('issue_due_date');
                    g_form.showFieldMsg('issue_due_date', getMessage('Issue due date cannot be in the past.'), 'error');
                } else {
                    createIssueModal(issueManager, issueManagerGroup);
                }
            }
        });
    }

    // Check related issues for the control
    if (g_form.getValue('source') === 'qa_finding' && g_form.getValue('recommendation') === '2') {
        var controlValue = g_form.getValue('item');
        g_form.addInfoMessage('controlValue:'+controlValue); // Get control sys_id
        if (controlValue) {
            g_form.addInfoMessage('hello');
            var test = new GlideAjax('sn_grc_advanced.CheckControlIssues'); // Call the Script Include
            test.addParam('sysparm_name', 'checkRelatedIssues');
           test.addParam('sysparm_control_sys_id', controlValue);
            test.getXMLAnswer(function(response) {
                alert('response:'+response);
               
                if (response === 'true') {
                    alert('hello');
                    var userResponse = confirm("Related Issues exist for the selected Control. Do you want to continue?");
                    alert('kk');
                    if (userResponse) {
                        alert('res');
                        createIssueModal(issueManager, issueManagerGroup); // Show modal
                    } else {
                        g_form.addInfoMessage("User canceled the process.");
                        return false;
                    }
                } else {
                    createIssueModal(issueManager, issueManagerGroup); // Proceed if no related issues exist
                }
           });
        }
    } else {
        createIssueModal(issueManager, issueManagerGroup); // Default action
    }
}
script include:
var CheckControlIssues = Class.create();
CheckControlIssues.prototype = {
    initialize: function() {},

    checkRelatedIssues: function() {
        var controlSysId=this.getparameter('sysparm_control_sys_id');
        if (!controlSysId) {
            return 'false'; // No Control field value passed
        }

        // Query the Issue table for related records with open states
        var issueGr = new GlideRecord('sn_grc_issue');
        gs.print('issues'); // Replace with your table name
        issueGr.addQuery('item', controlSysId);
        gs.print('issues1');
        issueGr.addQuery('state', 'IN', '0,1,2,5');
        gs.print('issues3');
        issueGr.query();

        if (issueGr.hasNext()) {
            gs.print('issues are present');
            return 'true'; // Related issues found
        }
        return 'false'; // No related issues found
    },

    type: 'CheckControlIssues'
};
please help thanks in advance
i have done changes in workspace client script only, the button is OOB onclick issue creates
4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@harinya 

so which line is causing issue in workspace client script?

did you add alert and debug?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Both are in same scope (Advanced core), that ui action is in OOB which is in Advanced core

harinya
Tera Contributor

harinya_0-1742732413452.png

@Ankur Bawiskar Thanks for Response,
upto hello it is going it is not going to script include script

@harinya 

is the ajax call happening?

script include and UI action are in same scope?

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