Dynamically changing $sp.getWidget options in Client Script

https://community.servicenow.com/thread/282435


 

CALLING Widget:

 

server:

(function() {  
    if (input.chosenDeptSysId.length == 32)  
    {  
        data.deptEditWidget = $sp.getWidget("bcp-dept-edit-widget", {"chosenDeptSysId":input.chosenDeptSysId});  
    }  
})();

 

client:

function($rootScope, $scope, $http, spUtil, $timeout, $location, $compile, $element) {  
    var c_this = this;  
    $scope.navigateToDept = function(id)  
    {  
        $scope.data.chosenDeptSysId = id;  
        c_this.server.update().then(function(response) {  
            $scope.data.chosenDeptSysId = '';  
        });  
    }  
}

html:

<div ng-if="!data.deptEditWidget">  
  <div class="innerDIV">  
    <table class="tableClass">  
      <tr>  
        <td colspan="2" class="headingTitle">Choose a department to edit</td>  
      </tr>  
      <tr>  
        <td class="columnTitle">Dept.</td>  
        <td class="columnTitle">Last Updated</td>  
      </tr>  
      <tr id="deptTR" ng-repeat="dept in data.deptList" ng-click="navigateToDept(dept.sysid)">  
        <td class="deptName">{{dept.name}}</td>  
        <td class="deptName">{{dept.updated}}</td>  
      </tr>  
    </table>  
  </div>  
</div>  
<div class="elementRow" ng-if="data.deptEditWidget">  
  <sp-widget widget="data.deptEditWidget"></sp-widget>  
</div>

 

CALLED Widget:

 

server:

(function() {  
    if (options)  
    {  
        var theDeptSysId = options.chosenDeptSysId;  
        if (theDeptSysId.length == 32)  
        {  
            /// blah blah do your stuff  
        }  
    }  
})();