Help needed in passing data from Client controller to Server script in widget.

dheeraaj
Giga Expert

Hi All,

I am trying to pass the below value from Client Controller to Server Script: The below script runs when a Link is Clicked on the service portal page.

HTML :
<tr ng-repeat="item6 in data.incitems_arr track by $index">
<td>
<h4><a ng-mousedown="c.show($index)" href="{{item6.url}}" target="_blank" class ="one"> {{item6.title}} </a></h4>
</td>
</tr>

Client Controller: 

this.show = function(i) {
c.data.i = i;
alert("You pressedlink: " +c.data.i); // This is alerting the right index number 
console.log('this is test');
this.server.get({
id:c.data.i
});
}

Server Script:

if (input.id) {

gs.info('hello is:'+success);  ---- > It is not going inside of if loop

}

Note: There is already a script running on load of the page, which is sending data to the server script

$scope.loadData = function(callback) {
$scope.data.action = "loadData";
$scope.server.update().then(function(){
console.log(c.data.articlesObject);
});
};

Help is appreciated.

Thank you.

1 ACCEPTED SOLUTION

dheeraaj
Giga Expert

Thanks all.

 

I got the answer that I needed.

View solution in original post

4 REPLIES 4

dheeraaj
Giga Expert

Thanks all.

 

I got the answer that I needed.

chidanandadhath
Kilo Guru

Hello,

 

try something like below:

Client Script:

function($scope, spUtil, $sce) {

var c = this;

this.show = function(i) {

c.data.i = i; // try to assign values outside of get.

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

}

}

}

 

Server Script : 

if (input.i == '??') {

// --->write your code here

}

 

Let me know if this works

 

Regards,

Dheeraaj

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);
  
})();