Hide/Show UI action on the basis of child task

Harshit Jamwal1
Mega Guru

Hi All,

I have a Button on the Change Request form named "Mark Complete".

I want that button only to be visible when all the Change Task (Child Task) of the same change request are close. 

Please help with the code where to write and what to write.

Thanks,

1 ACCEPTED SOLUTION

Sai Nagarjuna 1
ServiceNow Employee
ServiceNow Employee

Hi Harshit,

You need to create a UI action to have a button on the form and in the condition field set a condition that triggers a script include function.

Write you script in the script include and since the UI action condition field check the returned value.

If the returned value is true, then it will show the UI action on the form.

If the returned value is false, then the UI action doesn't shows up on the form.

So, Create a UI action and a Script include so that the UI action condition calls the Script include function. Both UI action and Script include images are attached for your reference.

Note: This doesn't call any client script as this ui action and script include are not client callable. You can make them client callable based on your use-case.

 

function MarkComplete() { }
	MarkComplete.prototype = {
		initialize: function () {
		},
		GetChangeTasks: function (parent) {
			var gr = new GlideRecord('change_task');
			gr.addQuery('parent',parent);
			gr.query();
			if(gr.next()){
				var gk = new GlideRecord('change_task');
				gk.addQuery('parent', parent);
				gk.addQuery('state', '!=' ,'3');
				gk.query();
				if(!gk.next()) {
					return true;
				}
				return false;
			}
			else {
				return false;
			}
		},
		type: 'MarkComplete'
	};

View solution in original post

2 REPLIES 2

Sai Nagarjuna 1
ServiceNow Employee
ServiceNow Employee

Hi Harshit,

You need to create a UI action to have a button on the form and in the condition field set a condition that triggers a script include function.

Write you script in the script include and since the UI action condition field check the returned value.

If the returned value is true, then it will show the UI action on the form.

If the returned value is false, then the UI action doesn't shows up on the form.

So, Create a UI action and a Script include so that the UI action condition calls the Script include function. Both UI action and Script include images are attached for your reference.

Note: This doesn't call any client script as this ui action and script include are not client callable. You can make them client callable based on your use-case.

 

function MarkComplete() { }
	MarkComplete.prototype = {
		initialize: function () {
		},
		GetChangeTasks: function (parent) {
			var gr = new GlideRecord('change_task');
			gr.addQuery('parent',parent);
			gr.query();
			if(gr.next()){
				var gk = new GlideRecord('change_task');
				gk.addQuery('parent', parent);
				gk.addQuery('state', '!=' ,'3');
				gk.query();
				if(!gk.next()) {
					return true;
				}
				return false;
			}
			else {
				return false;
			}
		},
		type: 'MarkComplete'
	};

How do I call the script from the UI action.
I'm doing a similar constraint for problems. The problem cannot be solved if you have open tasks.