How to pass a value from Client Script to Server Script in widget Service portal ?

gowthamram
Kilo Contributor

Hi,

In Client script, created a variable whose value is URL of the Service Portal. How to pass that value to the Server Script in widget.

 

Thanks in Advance.

7 REPLIES 7

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Could you give us more information and post the code that you have so far?

If you're wanting to send something to the server from the client in a Service Portal widget, there are a few methods to do that: server.update(), server.get(), and server.refresh().

https://docs.servicenow.com/bundle/kingston-servicenow-platform/page/build/service-portal/reference/...

Priyanka136
Mega Guru

Hi gowthamram,

Refer this link ,which will helps you to clear your doubts. :-

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

I hope this helps. Please mark correct/helpful based on impact....!!!!

Warm Regards,

Priyanka

find_real_file.png

www.dxsherpa.com

 

patricklatella
Mega Sage

You can pass a value from the client script to the server script in a widget as follows:

 

Say you have a string value that you want to pass from the client to the server, for example to update the short description on an INC...you set the value as follows:

 

in Client script:

c.data.short_description = 'this is my new short description';

 

in the Server script this translates to 'input.short_description'.

 

So if running a GlideRecord in the server script, it could look like this:

 

var inc = new GlideRecord('incident');

inc.addQuery('number', 'your INC number');//just for an example

inc.query();

 

if(inc.next()){

inc.short_description = input.short_description;//this is the value passed from the client

inc.update();

Input.short_description is showing as warn in console.log