- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2020 12:06 PM
I've created a test page for with the OOTB widget-form, and a newly created one for displaying a blue button (as below, in the top right) in a single column.
I'd like to have the button open a modal window, with a new record on the same table, with the parent field filled in.
For starters, I'd like to have it open the same record that is already opened in widget-form - which takes the sys_id and table from URL parameters (as seen in Server Script of my own). However, it seems that it doesn't accept the sys_id and table I pass from my widget via the data object.
Is there a simple mistake that I'm making? I'd appreciate hints on how to fill the fields in afterwards as well.
HTML
<div class="row">
<button class="col-md-8 btn btn-info" ng-click="c.modalButtonClick('widget-form')">Modal button</button>
</div>
Client Script
function($uibModal, spUtil, $scope, $rootScope) {
/* widget controller */
var c = this;
var data = c.data;
//console.info($scope);
c.modals = {};
c.widgets = {};
c.modalButtonClick = function(widgetName) {
var open = function(obj) {
//console.info(obj);
$uibModal.open({
template: obj.template
});
}
spUtil.get(widgetName,
{"sys_id": data.sys_id, "table": data.table}
)
.then(response => open(response));
};
}
Server Script
(function(input, data) {
data.table = $sp.getParameter("t") || $sp.getParameter("table") || null;
data.sys_id = $sp.getParameter("sys_id") || "-1";
})();
Solved! Go to Solution.
- Labels:
-
Service Portal Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2020 09:56 PM
I ended up finding spModal.open({}), using widgetInput key to define the data object, documented here:
https://developer.servicenow.com/dev.do#!/reference/api/newyork/client/SPModal-API#SPM-open_O
It worked both as:
widgetInput: c.data,
and
widgetInput: {sys_id: c.data.sys_id,
table: c.data.table},

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2020 12:44 PM
Hi,
sputil.get accepts only 1 argument which will be the widget id.
So in the widget, try to access these values directly
$sp.getParameter("sys_id")
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2020 09:54 PM
Why are the docs saying a different thing?
- https://docs.servicenow.com/bundle/newyork-application-development/page/app-store/dev_portal/API_reference/spUtil/concept/spUtilAPI.html
"spUtil - get(String widgetId Object data)" - https://docs.servicenow.com/bundle/newyork-servicenow-platform/page/build/service-portal/concept/c_NestedWidgets.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2020 09:56 PM
I ended up finding spModal.open({}), using widgetInput key to define the data object, documented here:
https://developer.servicenow.com/dev.do#!/reference/api/newyork/client/SPModal-API#SPM-open_O
It worked both as:
widgetInput: c.data,
and
widgetInput: {sys_id: c.data.sys_id,
table: c.data.table},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2020 05:04 PM
If you used spModal, what did you use on the widget end to display the form? I haven't had much luck with sp-model.