How to pass value from client controller to server controller in portal widget ?

Snehal13
Kilo Sage

This is not working. Getting undefined in server script

Client code 

api.controller = function($scope) {
    /* widget controller */
    var c = this;
    

    this.show = function(i) {

        c.data.i = 'this is my short description';

        c.server.get().then(function() {
            c.data = {}
        });

    }

}


//};

 

Server code

 

(function() {

    gs.info("client="+input.i);
  
})();

 

3 REPLIES 3

Sainath N
Mega Sage
Mega Sage

@Snehal13 : Please refer the below community article. It has good examples along with script examples that will help you.

https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-serv...

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Snehal13
Kilo Sage

None of the solutions worked. Already tried that

siva krishna M2
Tera Guru

Hello @Snehal13 ,

 

Please use below codes on client side and server side

 

Client side code:

 

api.controller = function($scope) {
/* widget controller */
var c = this;

this.show = function(i) {

c.data.i = 'this is my short description';

// passing the string value through I paramter to string side

c.server.update() // to trigger server script

}

})

 

Server side code:

 

if(input)

{

gs.addInfoMessage(input.i) 

// this is my short description will come in message

}

 

If it helps click on like icon and mark it as accepted