Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Pass the value from client script of widget to server script of same widget in service portal.

raja_5
Tera Expert

Hi Experts,

 

Iam trying to pass the value accNm from client script of widget A to server script of same widget in service portal

 

 

Client script 

   $scope.showaccount = {};
$scope.$on('getaccount', function(event, accNm) {
    $scope.showaccount.accNm = accNm;
    
     // Call the server-side script with the accNm value
    c.server.update({ accountNm: accNm }).then(function(response) {
        // Handle the response from the server-side script
        console.log(response.data);
    });
    
});
 
 
Server script :
 
var accountNm= input.accountNm;  ( accountNm is showing as undefined)
 
Please suggest
 
 
6 REPLIES 6

Ahmmed Ali
Giga Sage
Giga Sage

Hello @raja_5 

 

Try below statements:

client: 

 
    
//You need to put data in c.data object before calling server script 
     c.data.accName = "Test Value";
    c.server.update().then(function(response) {
        // Handle the response from the server-side script
        console.log(response.data);
    });
 
Server:
read it as 
var accName = input.accName;
 
Check with above static value first and if it works, then check with your dynamic value from event.
 
If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Hi @Ahmmed Ali 

Thank you for your response

 

accNm value is still showing as undefined 

Can you post your client and server script here?

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Client script     
   $scope.showaccount = {};
$scope.$on('getaccount'function(event, accNm) {
    $scope.showaccount.accNm = accNm;
    c.data.accNm=accNm;
     // Call the server-side script with the accNm value
      c.server.update({
        accNm: accNm
    }).then(function(response){
  // Handle the response from the server-side script
 
  console.log(response.data);
});
    
});

 

 

 

 

 

 

 

Server script :

var accName = input.accName;