How can I pass a variable from client script to server script in a service portal widget?

Marton
Kilo Expert

I have built a query on client side, I want to use it on the server side querying process, is there a way to just pass that variable to server script?

6 REPLIES 6

Alberto Consonn
ServiceNow Employee
ServiceNow Employee

Hi,

please check the following thread:

https://community.servicenow.com/community?id=community_question&sys_id=9db3db1adb00efc023f4a345ca96...

If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.

Thank you

Cheers
Alberto

The only solutions I found only set a parameter for a function. I want to get a string variable from client script.

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 intial load

 

}

Saif Al-Bashiti
Mega Expert

Hi Marton,

First of all , its very easy to pass any values from Client-Script to Server-Side , i will show to you how you can do that in a simple way : 

* Example 

( Client Side ) : 

c.data.ThisIsYourVariable = false;

if ( 3 > 2 ){

 c.data.ThisIsYourVariable = true ; // Use C.Data.X to Make your variable ready to pass to server-side

}

( Server Side ) : 

console.log(input.x); // this console.log will print true 

 

THAT ALL 🙂 BEST OF LUCK