The CreatorCon Call for Content is officially open! Get started here.

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

Strange... out of clues a bit. When I execute exactly the same, upon opening the Catalog Task I get immediately the info messages:

find_real_file.png

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

Yea, im not sure whats going on.

I've attached the Business Rule and Client Script from my PDI, which are both working.

Since you mention the Client Script is not showing the addInfoMessages on your screen, you have to look into what's different/wrong on your instance? For example look at the Chrome console, are there errors thrown? I mean, such a simple onLoad client script which starts with displaying a message, doesn't work on your instance?

You might also perform a cache.do. Though I wouldn't think this might be an issue. (type cache.do + ENTER in the navigator, or /cache.do in the URL).

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,

I did some digging and found that there was a business rule already in place to populate the scratchpad, i assume i could modify this to attempt to get everything working:

(function() {

g_scratchpad.is_admin = gs.hasRole('admin');
g_scratchpad.is_grpmem = u_isGroupMember(gs.getUserID(), current.assignment_group.sys_id);
g_scratchpad.is_grpmgr = (gs.getUserID() == current.assignment_group.manager);
g_scratchpad.u_cancellable = current.u_cancellable;
g_scratchpad.pending_approvals = false;
g_scratchpad.state = current.state;
g_scratchpad.active = current.active;

var dateStopUsingPending = new GlideDateTime("2014-12-18 00:00:00");
var dateItemCreated = new GlideDateTime(current.request_item.opened_at);
g_scratchpad.use_pending = dateStopUsingPending.compareTo(dateItemCreated) > 0;

var approvals = new GlideRecord('sysapproval_approver');
approvals.addQuery('sysapproval', current.request_item.sys_id);
approvals.addQuery('state', 'requested');
approvals.addQuery('u_ad_hoc', true);
approvals.query();

if (approvals.next()) {
g_scratchpad.pending_approvals = true;
}

})();

Sure you could do that. Then only one place for scratchpad, nice.

Though the issue is more that your onLoad Client Script doesn't show even a g_form.addInfoMessage() (there's a addInfoMessage at the start of the script, and that's not even showing? so the Client Script is not starting I guess). So something is already wrong there. Maybe conflicting scripting?

Have a look at the Chrome Console. Are there any errors written while opening the 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