How to open a new record with filled in details in a modal window?

JeremiP
Tera Guru

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.

find_real_file.png

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";
})();
1 ACCEPTED SOLUTION

JeremiP
Tera Guru

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},

 

View solution in original post

5 REPLIES 5

asifnoor
Kilo Patron

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

 

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

JeremiP
Tera Guru

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},

 

4bode
Kilo Contributor

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.