Pass data from client side of UI Action to Server side script of same UI Action

Servicenow Use4
Kilo Guru

Hello experts!

I have a UI Action which has both client and server side codes..

The client side calls a script include using GlideAjax and fetches 3 arrays from script include, which will be displayed in a 'confirm' dialog box on client. On click of Ok, server side script of UI Action is called.

Now, I need to perform server side actions on those 3 arrays. My question is, how do I pass those 3 arrays from client side of UI action to server side of same UI action...?

I am stuck at this point.. please help..

thank you!

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

I would suggest this

1) Perform another GlideAjax once confirm box is clicked and send those 3 arrays to another script include function and do the processing

Then no need of server side in that UI action

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

I would suggest this

1) Perform another GlideAjax once confirm box is clicked and send those 3 arrays to another script include function and do the processing

Then no need of server side in that UI action

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Servicenow User 

If you still want to keep client + server then do this

1) When you are doing the Ajax call and it is returning those 3 arrays

2) in that script include function set the session data using this

gs.getSession().putClientData('myFirstArray', array1);
gs.getSession().putClientData('mySecondArray', array2);
gs.getSession().putClientData('myThirdArray', array3);

3) now in the Server Side of the UI Action get the session data like this

var array1 = gs.getSession().getClientData('myFirstArray');
var array2 = gs.getSession().getClientData('mySecondArray');
var array3 = gs.getSession().getClientData('myThirdArray');

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi.. I am not sure if this would work or not since I went ahead with creating another script include function as per your pervious suggestion and it worked fine..

I followed this approach and it worked fine... thanks for the suggestion.. 🙂