About UI page processing scripts

bonsai
Mega Sage

I want to run a server-side script using a client script on a UI page.

I know how to call a script include from a client script, but is it possible to call code written in a UI page's processing script from the UI page's client script?

3 ACCEPTED SOLUTIONS

Nilesh Wahule
Tera Guru

Hi @bonsai ,

 

For using direct server side logic in UI page, ServiceNow allows us to write a code in jelly script as below. 

 <g:evaluate>
 var userRoles = new GlideRecord('sys_user_has_role');
    userRoles.addQuery('user','${jvar_user_id}');
    userRoles.query(); 
  </g:evaluate>

There are 2 versions of the jelly script in the platform. Please refer to existing UI pages for more details. 

 

My recommendation would be to avoid the jelly script if it is not much of worth.

 

---------------------------------------------------------------------------------------------------

Please mark my answer as helpful/correct if it resolves your query.

Thanks,
Nilesh Wahule

---------------------------------------------------------------------------------------------------

 

View solution in original post

Ankur Bawiskar
Tera Patron
Tera Patron

@bonsai 

there are 2 ways

1) within client script of UI page use GlideAjax

OR

2) run server side script within processing script of UI page. remember for this to work you need to use <g:ui_form> and need to submit the form so that controls goes to UI page processing script

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

Juhi Poddar
Kilo Patron

Hello @bonsai 

UI page's processing script runs when the form is submitted, meaning it operates server-side after the client-side processing. To make a server-side call within a form, you should use GlideAjax.

GlideAjax allows you to call a Script Include from a client script, enabling you to run server-side logic while still interacting with the client-side form.

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You
Juhi Poddar

View solution in original post

8 REPLIES 8

yuvarajkate
Giga Guru

Have you tried using Glide Ajax?

Bert_c1
Kilo Patron

UIPages.html

Review there

Nilesh Wahule
Tera Guru

Hi @bonsai ,

 

For using direct server side logic in UI page, ServiceNow allows us to write a code in jelly script as below. 

 <g:evaluate>
 var userRoles = new GlideRecord('sys_user_has_role');
    userRoles.addQuery('user','${jvar_user_id}');
    userRoles.query(); 
  </g:evaluate>

There are 2 versions of the jelly script in the platform. Please refer to existing UI pages for more details. 

 

My recommendation would be to avoid the jelly script if it is not much of worth.

 

---------------------------------------------------------------------------------------------------

Please mark my answer as helpful/correct if it resolves your query.

Thanks,
Nilesh Wahule

---------------------------------------------------------------------------------------------------

 

Can scripts implemented in this way be run from a client script?