How to set embedded widget options via clint script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2022 02:55 AM
How can we set embedded widget options via client script
HTML Templates
<div class="form-group">
<p>
Embedded widget via Client Script
</p>
<sp-widget widget="c.clientScriptWidget"></sp-widget>
</div>
Client Script
function(spUtil){
spUtil.get('widget-cool-clock').then(function(response){
c.clientScriptWidget=response;
});
}
function(spUtil){
spUtil.get('widget-cool-clock',{c_color:"orange"}).then(function(response){ //not working
c.clientScriptWidget=response;
});
- Labels:
-
Service Portal Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2022 03:32 AM
Hi, You can do it in server side script -
$sp.getWidget('widget_id', options);
Please mark helpful/correct
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2022 04:03 AM
Yeah we can .... but is there any way to do with client script ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2022 02:00 PM
The Clock Widget loads everything via options. Settings options is only possible via $sp.getWidget. You can use this fact to replace the spUtil.get with this:
Server Script:
(function() {
if (input && input.widget && input.widgetOptions) {
data.widget = $sp.getWidget(input.widget, input.widgetOptions);
return;
}
})();
Client controller:
api.controller=function(spUtil) {
var c = this;
c.server.get({
widget: 'widget-cool-clock',
widgetOptions: { c_color: "orange" }
}).then(function(response) {
c.clientScriptWidget = response.data.widget;
});
};
Result:
Please let us know if you need further assistance, if not please mark the solving answer as the solution to close the thread.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2023 04:16 PM - edited 01-21-2023 04:16 PM
by SN documentation it is possible to set options via spUtil :
https://docs.servicenow.com/bundle/tokyo-servicenow-platform/page/build/service-portal/concept/c_Nes...
https://developer.servicenow.com/dev.do#!/reference/api/tokyo/client/spUtilAPI#SPU-get_S
ex:
spUtil.get('pps-list-modal', {title: c.data.editAllocations, table: 'resource_allocation', queryString: 'GROUPBYuser^resource_plan=' + c.data.sysId, view: 'resource_portal_allocations' }).then(function(response) { var formModal = response; c.allocationListModal = response; });
but it's not working with wigdet-cool-clock, aperantly not all widgets ServiceNow treats equaly.
PS thx for work around example.