Service Portal spModal: what can the "shared" option be used for?

ITSM Dev
Tera Expert

What can the "shared" option in spModal be used for and how?

It is shown in below example code

find_real_file.png

3 REPLIES 3

Mohith Devatte
Tera Sage
Tera Sage

Hello,

shared - a client-side object to share data with the embedded widget client script.

If you send some variable in that shared option you will be able to access it in the widget client controller script that you called in widget parameter

For more explanation and details please refer to below link https://developer.servicenow.com/dev.do#!/reference/api/sandiego/client/SPModal-API

 

Please mark me answer correct if you find it helpful

 

Mohith Devatte
Tera Sage
Tera Sage

HELLO

DID MY RESPONSE HELP IF YES PLEASE MARK MY ANSWER CORRECT AND HELPFUL . THIS WILL HELP OTHERS TOO WITH SAME QUERY

Upender Kumar
Mega Sage

Example

Html Template

<div>
  <button ng-click="c.onChangeSchedule()">
    Open
  </button>
  
  <div ng-if="c.selectedValue">
    You picked: {{c.selectedValue.text}}
  </div>
</div>

Client Script

function ($scope,spModal) {	
	var c = this;
	var shared = {};
	c.onChangeSchedule = function(){
		spModal.open({
			title: 'Select a value',
			widget: 'bec1438bdbf276009ed8f81d0f96193e',
			widgetInput: { hint: "Soup or Nuts?" },
			shared: shared
		}).then(function() {
			// Shared object was updated
			c.selectedValue = shared.selection;
		});
	}
}