Neeraj Sharma10
Tera Guru

Requirement : Make variables read only on both native and service portal form if priority field is set to critical on RITM table.

Challenges

  1. g_form refer to ritm fields on native view but  only variables on service portal form. i.e g_form.getValue('priority'); returns null on service portal form widget.

    Solution : Script Include (Savior) can return any value form any table.
    var CatalogUTILS = Class.create();
    CatalogUTILS.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    
    
        isCritical: function() {
            var ritm = this.getParameter('sysparm_ritm');
            var gr = new GlideRecord('sc_req_item');
            gr.get(ritm);
            return (gr.priority.toString() == '1' ? true : false);
    
    
        },
    
        type: 'CatalogUTILS'
    });


  2.  g_form.setVariablesReadOnly(true); is not supported on service portal. Reason... It is what it is!
    Solution: Catalog client script

    function onLoad() {
        if (window === null) {
    	var ritm  = getParameterValue('sys_id');
    	var ga = new GlideAjax('CatalogUTILS');
        ga.addParam('sysparm_name', 'isCritical');
        ga.addParam('sysparm_ritm', ritm);
        ga.getXML(checkCritical);
    
        function checkCritical(response) {
    		var isCritical= response.responseXML.documentElement.getAttribute('answer');
    		if(isCritical == 'true'){
            var allFields = g_form.getFieldNames();
            for (var fieldName in allFields) {
                g_form.setReadOnly(allFields[fieldName], true);
            }
    		}
    	}
        } else {
    		if (g_form.getValue('priority') == '1') {
            g_form.setVariablesReadOnly(true);
    		}
        }
    	
    	function getParameterValue(name) {  
        name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");  
        var regexS = "[\\?&]" + name + "=([^&#]*)";  
        var regex = new RegExp(regexS);  
        var results = regex.exec(top.location);  
        if (results == null) {  
            return "";  
        } else {  
            return unescape(results[1]);  
        }  
    }
    }​


    Make sure to Set UI type to ALL and Applies on Requested Items to checked.

 

 

Thanks for Reading
Cheers 🙂

 

Comments
ankit sharma1
Tera Contributor

the above script works for portal but since we had requirement to make it readonly on both native n portal views, we added one catalog client script simply

and that take care of native view also

function onLoad() {

if (g_form.getValue('priority') == '1') { g_form.setVariablesReadOnly(true); }
}

 

this is workaround but at least works

Version history
Last update:
‎07-15-2021 11:47 AM
Updated by: