how to hide the button

msc
Tera Contributor

hi 

ihave a requirement that, we need to hide the close task button  and close complete option in state field on change task when rfc record is created  on change request and change task short description contains System Test & Validation.

below  are the code i wrote  but here close task button some times is not hiding please give me your suggestion or can we take sysyid of the close task 

find_real_file.png

find_real_file.png

 

1 ACCEPTED SOLUTION

shloke04
Kilo Patron

Hi @msc 

Please find the steps you need to follow to achieve your requirement:

1) Create a Script Include and use the script as below:

var uiActionVisibility = Class.create();
uiActionVisibility.prototype = {
    initialize: function() {
    },
	
	buttonDisplay : function(changeID){
		var gr = new GlideRecord('u_charm_rfcs');
		gr.addQuery('FieldName',changeID); // Replace 'FieldName' witht he field which is present on your Charm Rfcs table which will be a Reference field and connecting to Change record
		gr.query();
		if(gr.next()){
			return false;
		}else{
			return true;
		}
	},

    type: 'uiActionVisibility'
};

Now Close task button present on Change Task you need to add the below line to your existing Script with an AND condition and pass the Change Request ID as shown below:

current.state < 3 && current.approval != 'requested' && !current.change_request.on_hold && new uiActionVisibility().buttonDisplay(current.change_request)

Let me know how you go with this:

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

19 REPLIES 19

Update as this

Script Include:

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

	charmexists: function(chgSysId)
	{
		var answer;
		var cursysid = chgSysId;
		var rfc = new GlideRecord('u_charm_rfcs');
		rfc.addQuery('u_cr_number', cursysid);
		rfc.query();
		if(rfc.next() && (!gs.hasRole("admin")))
		{
			answer = true;
		}
		else
		{
			answer = false;
		}
		return answer;

	},
	type: 'checkcharmrfc'
});

Ui action condition :

current.state < 3&& current.approval != 'requested'  && current.state != -5 && new checkcharmrfc().charmexists(current.change_request) && current.short_description.toString().indexOf('System Test & Validation')>-1)

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

but i have 2 task one is System Test & Validation

and another one is Solution Implement

i need to dispplay the close task ui action in  Solution Implement

 

msc
Tera Contributor

i need to display close task button in Solution Implement and system test validation task only when charm rfc is not created in cahnge request

msc
Tera Contributor

hi Ankur , for change request they have 2 task 

1.soultion implement task 

2.System Test & Validation

close task ui action will be visible only 

on fisrt task and  

second task cheking the rfc is not created the we have to display close task ui action

update the condition by checking the task type

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader