Dave
Dave

Reputation: 1277

ServiceNow: accessing widget option schema in mdDialog

I've cloned the OOTB widget-form, named it widget-form-md, and created an additional option schema for hideRelatedLists:

enter image description here

I have a separate widget that is embedding my cloned widget-form-md and hope to display it via a Material Design modal. My client script for the modal looks like this:

function x ($scope, $location, spUtil, amb, $mdDialog, $http, $window, $rootScope, $timeout){
var c = this;

c.newRequest = function() {
$mdDialog.show({
contentElement: '#hr_request',
parent: angular.element(document.body),
clickOutsideToClose:true
});
spUtil.get("widget-form-md", {
request_name: 'hr_request',
view: 'hr_request',
table: 'x_dnf_federal_hr_e_federal_hr_cases'
}).then(function(response) {
c.hr_request = response;
});
};
}

What is the correct syntax to pass in my option schema into the spUtil? I've tried

spUtil.get("widget-form-md", {
request_name: 'hr_request',
hideRelatedLists: true
view: 'hr_request',
table: 'x_dnf_federal_hr_e_federal_hr_cases'
})

and

spUtil.get("widget-form-md", {
request_name: 'hr_request',
options: {hideRelatedLists:true},
view: 'hr_request',
table: 'x_dnf_federal_hr_e_federal_hr_cases'
})

Neither of them worked and I can't seem to find any documentation out there on how to do this. Any suggestions? Thanks!

Upvotes: 2

Views: 933

Answers (1)

Gordon Mohrin
Gordon Mohrin

Reputation: 609

First: Option Schema is used to configure a widget via a table: https://dxsherpa.com/blogs/widget-options-schema-in-service-portal/

The Solution to the missing parameters, which don't show in the options of the called widgets was here: https://community.servicenow.com/community?id=community_question&sys_id=ea83c365dbd8dbc01dcaf3231f9619d2

When a widget is called using spUtil (client) then the parameters passed are accessed using "input".

When a widget is called using $sp (server) then the parameters passed are accessed using "options"

Since the call the widget with spUtil, we have the data on the server in the input object. Therefor in the server of the called widget:

data.requestName = input.request_name;
data.hideRelatedLists = input.hideRelatedLists;
// or the short version, if widget also gets parameters from URL and options:
data.requestName = $sp.getParameter('requestName ') || options.requestName || input.requestName;

It's a shame this is not described in the official documentation for it: https://developer.servicenow.com/app.do#!/api_doc?v=london&id=spUtilAPI

Upvotes: 2

Related Questions