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

Zack S
Giga Contributor

widgetInput has not been working reliably for me. Passing sys_id seems to work, but it is not showing up on the input object. That is, my input object does not have what I pass into widgetInput, but things like widget-sc-cat-item seem to be able to see it properly. 

Has anyone else found this issue?