Call an widget when click on a button in a form

Lavanya Nagendr
Giga Guru

Hi All,

 

Requirement: When the user click on an form button which needs to invoke a widget in an pop window manner.

 

I have 2 ways to implement but i am not sure how to invoke the widget from an ui action. Kindly help me on this.

 

1. Via Service Portal

HTML:

 

<a target="_blank" ng-href="{{options.href}}" class="c-btn--secondary':!a.primary && a.form_style=='unstyled">{{data.buttonMsg}}</a>

 

SERVER SCRIPT:

 

data.buttonMsg = gs.getMessage(options.button_text || "Take Attestation");

 

 

2.Via Native Ui Action:

 

Screenshot 2023-11-20 at 6.28.48 PM.png

 

window.location.href = 'http://www.google.com';

 

 

My widget link:

 

?id=take_attestion

 

5 REPLIES 5

Ethan Davies
Mega Sage
Mega Sage

I think this is what you're looking for. The below link should help you create a widget and call it from the UI Action.

 

https://www.servicenow.com/community/itsm-forum/ui-action-pop-up-modal-window/m-p/581585

Hi Ethan,

 

I already have an 'Widget' which displays some questions for attestation purpose. I need to invoke that widget via a button(<button>) or an native view ui actions. Is there any way to achieve this, if so Kindly help me on this.

 

Thanks!

Hey - Yes, there is. If your 'widget' is a Service Portal then you will not be able to call it, you will need to re-create it for it to work in the native UI using a UI Page. Your UI Action needs to be client-callable and you need to use a GlideDialaogWindow to open it as a pop-up, and then call your UI Page.

 

I am not going to re-type everything from other posts, but literally, everything you need is in this guide if you follow it.

 

https://www.servicenow.com/community/developer-articles/custom-ui-page-in-a-popup/ta-p/2319550

Hi @Ethan Davies ,

 

So we already have an ui action which is client callable and is doing the work as same as the widget, but since its an client callable ui action i couldn't able to call the ui action to portal that is when we created the widget that would do the same action as the native ui action. Is there any way we can call the widget when clicking on a button/text link from service portal?

 

Currently i have created a link in my custom widget 

 

HTML: 

<button ng-click="c.openAttest(this)" type="button" class="c-btn m-r-xs" ng-class="{'c-btn--primary':a.primary || a.form_style=='primary','c-btn--danger':a.form_style=='destructive','c-btn--secondary':!a.primary && a.form_style=='unstyled'}">{{data.buttonMsg}}</button>

Client controller:

 c.openAttest = function(element){
		window.location = element.data.url;
	};

 

Server script:

data.url = "xxx?id=take_survey&instance_id="+data.id.toString();

 

Is there any way we can make this link to call my widget instead of an url?

 

Thanks!