Making variable visible after task is closed

servicenow14710
Tera Expert

Hello developers,

I need a suggestion as if it is possible to make custom variable visible on RITM once task is closed complete(this variable will be visible on catalog task).Any help is appreciated, Thanks!

6 REPLIES 6

Hi @servicenow14710 ,

 

instead of going the other way around, you can simply create UI Policy on RITM table which make the field visible and mandatory when the ritm state is closed.

 

I hope this helps..


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

Tai Vu
Kilo Patron
Kilo Patron

Hi @servicenow14710 

Let's try to make an OnLoad Client Script and an Ajax call to identify the completed catalog task, then make the variable visible accordingly.

Sample below.

#Script Include

var CLCatalogItemUtilAJAX = Class.create();
CLCatalogItemUtilAJAX.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    isTaskCompleted: function(){
		var ritm = this.getParameter('sysparm_request_item');
		var grSCTASK = new GlideRecord('sc_task');
		grSCTASK.addQuery('request_item', ritm);
		grSCTASK.addQuery('state', 3);
		//Suppose the RITM has multiple Catalog Tasks. Apply your own query below to get that specific task
		//grSCTASK.addQuery('short_description', '<your_task_short_description>');
		grSCTASK.query();
		return grSCTASK.hasNext();
	},

    type: 'CLCatalogItemUtilAJAX'
});

 

#Client Script

function onLoad() {
    var ga = new GlideAjax('CLCatalogItemUtilAJAX');
    ga.addParam('sysparm_name', 'isTaskCompleted');
    ga.addParam('sysparm_request_item', g_form.getUniqueValue());
    ga.getXMLAnswer(function(answer) {
        g_form.setDislay('<your_varialbe_name>', answer);
    });
}

 

Cheers,

Tai Vu