HIde 'Closed Cancelled' state on catalog task when catalog item has the Cancellable checkbox checked

othomas1
Kilo Guru

Hello everyone,

I thought this one was pretty straightforward so i made a client script, but when a catalog item has the Cancellable checkbox checked, i need the associated catalog tasks to not show the closed cancelled state as a choice in the dropdown, the script below is not working:

 

function onLoad() {
if(g_scratchpad.u_cancellable == 'false') {
g_form.removeOption('state', '4');
}

}

Can someone spot what my script is missing?

1 ACCEPTED SOLUTION

I was thinking, since the Business Rule and Client Script itself are oke, and the addInfoMessage is simply not displayed, and you don't experience this in general with other Client Scripts:

Do you have other Client Scripts on the same form? Might these be interfering? Have you tried disabling these and retesting to see if the new Business Rule and Client Script are working? If so, then you know there's an issue or conflict with the existing Client Scripts on your form.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

63 REPLIES 63

And the result 🙂

find_real_file.png

State 4 / Closed Incomplete, not visible if Cancellable on the Catalog Item is true.

If you meant Requested Item, obviously slightly change the Business Rule.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

You did mention Catalog Item, so that's what i've setup the Business Rule for. In case you actually meant Requested Item, here's the code for the Business Rule:

g_scratchpad.cancellable = current.request_item.u_cancellable;

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Chaitanya Redd5
Tera Guru

Hi,

You need to setup a Display Business Rule to setup a Scratchpad variable.

Also you can go via Client Script and a Script Include.

Client Script:

function onLoad() {
	//Type appropriate comment here, and begin script below
	var ga = new GlideAjax('CancellableItem');
	ga.addParam('sysparm_name','cancelitem');
	ga.addParam('sysparm_ritm',g_form.getValue('request_item'));
	ga.getXML(callback);
}
function callback(response){
	var answer = response.responseXML.documentElement.getAttribute("answer");
	if(answer=='true')
		g_form.removeOption('state','4');
	
	else
		g_form.addOption('state','4');
}

Script Include

Name: CancellableItem

Client Callable: True

Script:

var CancellableItem = Class.create();
CancellableItem.prototype = Object.extendsObject(AbstractAjaxProcessor, {
cancelitem: function(){
	var ritm= this.getParameter('sysparm_ritm');
	var gr = new GlideRecord('sc_req_item');
	gr.get(ritm);
	if(gr.isValidRecord()){
		return gr.u_cancellable;//replace u_cancellable with the checkbox field name
	}
	
},
    type: 'CancellableItem'
});

Kindly mark my answer as Correct and Helpful based on the Impact.

Regards,

Chaitanya

If going for GlideAjax, go for the far more efficient getXMLAnswer. Instead of the less efficient getXML.

Read about this in an article I wrote recently:
getXMLAnswer vs getXML

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Hi Mark,

Does it matter that the checkbox is on the catalog item itself which is on the sc_cat_item table and not on the sc_task table like catalog tasks? im asking to better understand how these tables work together

find_real_file.png