Can we use c.server.update().then(function(){} twice in client script?

Swati44
Kilo Expert

Hi All,

Can we use "c.server.update().then(function(){}" twice in client script of a widget in service portal. 

Requirement is to pass the values from html to server, so am taking the changed input value from html and passing it to server script via client script. At first when I call c.server.update().then(function(){}, it works fine. But second time it is not.

Please help me in understanding.

 

Thanks & Regards,

Swathi.

3 REPLIES 3

Swathi12
Tera Expert

Hi,

 

We can call c.server.update() multiple times.

 

If you want to save multiple input values from html you can bundle it in array and pass it across to server with c.server.update()

 

Please do mark this answer helpful , if it answered you question.

 

Regards,

Swathi

Bhagyashree8
Kilo Guru

Hi,

 

If your requirement is to send multiple values at the same time then sent it as Object.

or setting this to data object separely.

c.data.firstVal = "one";

c.data.secondVal = "two";

 

then on server side you can access it as input.firstVal and input.secondVal

 

OR if you want to make sequential call to server then do below.

c.data.firstVal = "one";

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

  c.data.firstVal = resp.firstVal;  //will get you value "one"

  c.data.secondVal = "two";

  c.server.update();

})

 

On Server script you need to persist value of firsVal. like below

after you use input.firstVal , write last line like

data.firstVal = input.firstVal;

 

Hope all this makes sense.

 


Mark my ANSWER as CORRECT / HELPFUL if it served your purpose.

Hi,

 

I have an issue with widget server script.  I am adding comments in RITM. Everyting is working fine but comments are adding multiple times.

 

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

 

please suggest