How to pass parameter from client controller to server controller

Sin
Giga Expert

Hi all.Am working on service portal,trying to pass values from client side to server side. Tried the following code but am getting nothing on console log.

Client side:

 

function() {
/* widget controller */
var c = this;
c.data.val='abcdefg';

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

})

}
}

 

Server side:

 

(function() {

if(input)
{
console.log(input.val);
}

})();

 

whats wrong with my code?Please advice!!

1 ACCEPTED SOLUTION

Shweta KHAJAPUR
Tera Guru

Try client script as beloow,

function() {
/* widget controller */
var c = this;

c.server.get({
val:'abcdefg'
			

}).then(function(r){

});

}
}
 

View solution in original post

7 REPLIES 7

Raj68
Mega Guru

Hi sana,

 

You can use c.server.update to send the data to server as mentioned below.

 

function($scope) {    

       var c = this;

   c.data.abc='Any Name';

       c.update = function() {

              c.server.update().then(function (response) {

   c.data = {};

   })

       }

 }

 

 

Server side you can use

 

if(input)

 {

 gs.log(input.abc);

 }

 else

 {

 //Code for initial load

 }

 

NOTE: Mark correct or helpful if it helps you.

 

 

Warm Regards,

Raj patel

 

Prins Kumar Gup
Giga Guru

Hi Sana,

 

Please write below code:-

HTML PART:-

<div>
<!-- your widget template -->
<input type="submit" value="Insert" ng-click="c.update()">
</div>

--------------------------------------------------------------------------------------------

Client Script:-

function() {
/* widget controller */
var c = this;

c.data.val="Testing";

c.update = function() {
c.data.action = "Test"
c.server.update().then(function (response) {
c.data = {};

})

}
}

----------------------------------------------------------------------------------------------------------

Server Script:-

(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
if(input.action == "Test"){

gs.addInfoMessage(input.val);
}
})();

 

Regards

PKG