How to pass parameters from Client Side to Server Side in one UI Action.

sakata kenichi
Kilo Contributor

How to pass parameters from Client Side to Server Side in one UI Action.

However, the parameter is not a table field.

UI Action

// Client Side Script
function onClickUIAction(){
  var askResonDialog = new GlideModal("askResonDialog");
  askResonDialog.on("closeconfirm", function () {
    
    // I want to pass this parameter to the server.
    var reason = this.getPreference("reason");

    gsftSubmit(null, g_form.getFormElement(), "thisUIAction");
  });
  askResonDialog.render();
}

// Server Side Script
if (typeof window == 'undefined') {
  // I want to receive a "reason" here.
}
1 ACCEPTED SOLUTION

Harsh Vardhan
Giga Patron

this.getPreference() will not work in client side , you have to pass it in your server side code. 

if you want to use getPreference() use glide ajax here. 

 

Here you have to create one Client callable script include and then use that script include using glide ajax into your ui action client side script. 

kindly have a look on glide ajax example doc link below. 

 

https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/script/server_scripting/reference...

View solution in original post

2 REPLIES 2

Harsh Vardhan
Giga Patron

this.getPreference() will not work in client side , you have to pass it in your server side code. 

if you want to use getPreference() use glide ajax here. 

 

Here you have to create one Client callable script include and then use that script include using glide ajax into your ui action client side script. 

kindly have a look on glide ajax example doc link below. 

 

https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/script/server_scripting/reference...

Patricio Javier
Tera Contributor
//Client Script

api.controller = function ($scope, $rootScope, $timeout, $interval) {

    /* widget controller */
    var c = this;
 
  this.saveData = function(){
        var payload = {};
        payload.data = {};
        $scope.data.param = 'data';
        $scope.data.action = 'saveData';
        payload.data["Action"] = "SaveData";
        $scope.server.update();
   
  };
 
  };
};
 
 
//Server Script
 (function () {

        if (input && input.action == 'saveData' ) {
             gs.addInfoMessage(input.param);
        }
 
})();