spModal - How to pass values from spModal to original widget

Saran Ramayanam
Tera Expert

Hi Everyone,

 

I am using spModal in page to open a new record in a table (opening form widget in spModal), i have passed sys_id,table name and view in parameters(WidgetInput), how can i get output of that form after creation say sys_id??? and how to close the modal after selecting save or submit in embedded widget

 

spModal.open({
            title: label,
            widget:'widget-form', //FORm WIDGET
	buttons: [{label:'${Close}', cancel: true}],
	size:"md",
           widgetInput: {sys_id : -1,table : TABLE_NAME,view : 'new_record',disableUIActions : false}
        }).then(function(){
            console.log('widget dismissed');
        })      
5 REPLIES 5

Rob Humphries
Tera Expert

This is from quite a long time ago, so you probably aren't looking for an answer anymore, but incase anyone else finds this post like I did...

 

When you use spModal.open() one of the options in the config you pass in is called "shared". You can then access this shared object in your modal widget client controller using $scope.widget.options.shared. Whatever you set it to will then be available in your then() callbacks.

 

Example client script

function onLoad() {
   // create a variable to send to the widget which it can update and send back
   var sharedVariable = {one:"Something"};

   //widget to load in the modal
   var widgetId = "modal-select";
   var widgetInput = {};

   //open the modal
   spModal.open({
            title: 'Displaying widget ' + widgetId,
            widget: widgetId, 
            widgetInput: widgetInput || {},
            shared:sharedVariable //include the shared variable
        }).then(function(response){
            console.log(sharedVariable) //this log statement will show any updates you do with the modal widget
      }) 
}

 

Example widget client controller

api.controller=function($scope) {
  /* widget controller */
  var c = this;
  c.shared = $scope.widget.options.shared;
  c.shared.answer = "The widget client controller added this to the variable"
};

 

You can use this method with modal widgets opened from other widgets or opened from portal client scripts or catalog client scripts.