Make the CIM Task State readonly on the basis of the CIM request State

SanikaK
Tera Contributor

I have a requirement where I have a CIM request table, In the table there is a related list for CIM task table.

In the CIM task table the 'State' field should readonly when the state of the CIM request table is Accepted or Approved or Assess, Values(-6,-5,-4)
Please find the below SI & CS 
Note: - the alert is giving empty value

Script Include

var CIMApproval = Class.create();
CIMApproval.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    approvestate: function() {
        var result ='';
        var sysId = this.getParameter('sysparm_sys_id');
        //var st = this.getParameter('sysparm_state');
         if (!sysId) {
             return '';
         }
        var gr = new GlideRecord('sn_cim_register');
        if (gr.get(sysId)) {
            result = gr.getValue('state');  
        }
        return result;

    }


});

OnLoad Client Script 
function onLoad() {
    //Type appropriate comment here, and begin script below
    // var state = g_form.getValue('state');
    var ga = new GlideAjax('CIMApproval');
    ga.addParam('sysparm_name', 'approvestate');
    ga.addParam('sysparm_sys_id', g_form.getUniqueValue());
    // ga.addParam('sysparm_state', '-6');
    // ga.addParam('sysparm_state', '-5');
    // ga.addParam('sysparm_state', '-4');
    ga.getXML(approve);

    function approve(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        if (answer === '-6' || answer === '-5' || answer === '-4') {
            g_form.setReadOnly('state', true);
        }


        alert('state: ' + answer);
    }
}




1 REPLY 1

Mark Manders
Mega Patron

What happens if you dotwalk to the request from a UI policy condition?


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark