UI action visibility

juveriya307
Giga Contributor

there is a UI action - "Request PIR" on change form which creates a problem and problem task record when clicked. Now i want to hide this UI action link when there is already a problem record attached to change record. This related link should only be visible if there is no problem record attached to the change record.

1 REPLY 1

dhanrajb
Tera Guru

Hi @juveriya307 ,

 

Try something like below. You can achieve this using onLoad client script. Modify the script according to your requirements.

 

Client Script:

var gaCheckProblem = new GlideAjax('check_for_problem');
gaCheckProblem.addParam('sysparm_name', 'checkProblem');
gaCheckProblem.addParam('change_sys_id', g_form.getUniqueValue());
gaCheckProblem.getXMLAnswer(getResponse);

function getResponse(response) {
    $$('button[data-action-name^state_model]').each(function (e) {
        if (response == true) {
            e.hide();
        } else {
            e.show();
        }
    });
}

 

Script include:

//check client callable in script include and write the script
var check_for_problem = Class.create();
check_for_problem.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    checkProblem: function () {
        var answer = false;
        var changeValue = this.getParameter('change_sys_id');
        var grProblem = new GlideRecord('problem');
        grProblem.addQuery('rfc', changeValue);
        grProblem.query();
        if (grProblem.next()) {
            answer = true;
        }
        return answer;
    },
    type: 'check_for_problem'
});

 

Regards,

Dhanraj.