How to create a simple button on a catalog item?

Subhashree3
Giga Contributor

Hi All,

We have a requirement to create a button on the catalog item that will only be visible when the user opens in service portal.I tried as per below step but I observed instead of service portal, its appearing at the RITM level. Could you please let me know how to implement a custom button on catalog item only?

steps i followed:

 1. Created a UI Macro under System UI.

//XML Code

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<div>
<button type="button" class="btn btn-default btn-block" onclick="alert('Hello world!')">Next</button>
</div>
</j:jelly>

2. Created a Widget under Service Portal

//HTML Code

<div>
<!-- your widget template -->
<button type="button" class="btn btn-default btn-block" onclick="alert('Hello world!')">Next</button>
</div>

*For now I have not added any functionality under Client cOntroller and Server script

3. Created a variable in the catalog item of Macro type and mapped this UI macro and WIdget I created.

Instead of appearing at the Catalog Item, its appearing under RITM level. Please let me know your suggestions.

find_real_file.png

Thanks

1 ACCEPTED SOLUTION

In variables keep macro and summary macro field empty.

find_real_file.png

 

 

and Now add the widget as shown below

View solution in original post

17 REPLIES 17

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Subhashree,

you can have onLoad client script and then check whether url is of service portal

if yes then show that ui macro variable; if not then hide it

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Hi Ankur,

 

Thanks for your response.

I tried creating a new catalog client script in that catalog item. But I am not seeing any option to add the Macro in the client script.

find_real_file.png

Could you please elaborate on this approach? Please note I have created a variable, not a variable set on which I can apply this client script.

Hi Subhashree,

in the onLoad first get the URL; by default let that variable show up

select applies to catalog item and requested item both checkbox as true

if it is service portal then show; also you want this to be hidden in RITM  view

function onLoad(){

var url = this.location.href;

var isServicePortal = url.toString().indexOf('sp');

var isRITMView = url.toString().indexOf('sc_req_item');

if(isServicePortal == -1 || isRITMView != -1){

// either this is not sp page or this is ritm page so hide it

g_form.setDisplay('variables.<variableName>', false);

}

 

}

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Hi Ankul,

This is working fine in the catalog item but at the RITM level the button is still appearing.

I checked the url and its of ServicePortal type. so I modified the code as below.

find_real_file.png

Is there any other way which will help me to hide at RITM level?

Thank you.