Differentiate client scripts and server scripts in UI actions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2020 12:11 AM
Differentiate client scripts and server scripts in UI actions?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2020 12:21 AM
Kindly have a look on below blog, worth to read this. detail explanation with an example.
https://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2020 12:24 AM
HI,
https://www.servicenowelite.com/blog/2014/2/19/client-vs-server
https://www.youtube.com/watch?v=TqSI2FcU8iE
https://www.youtube.com/watch?v=3A0qeS4rAYw
Thanks,
Ashutosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2020 12:28 AM
Hi Ram,
UI actions in servicenow can run on server side and client side both, Mostly requirement is of to run UI action on server side. You can add UI actions to tables and database views that are in the same scope.
https://www.basicoservicenowlearning.in/2020/01/ui-action-in-servicenow.html
If my answer helped you in any way, mark answer as helpful and correct.
Thanks and regards,
Megha

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2020 12:40 AM
Hi
The action name should be unique with respect to UI action, but it can be anything. Make sure you do no give any space in the action name field.
Onclick function runs on the client side and the rest of the functions that are written executes in the server side.
gsftSubmit(null, g_form.getFormElement(), "ui action id") triggers the UI Action which is specified in the 3rd parameter, which is the action name/element id.
It is mostly used in UI actions that have a client side and a server side script.
At the end of the client side script, you call gsftSubmit in order to trigger the UI Action again - this time running only the server side code.
EXAMPLE:
Name: -Button Name-
Action name: -button_action_name- (Should be unique per button on form and gets called from the UI Action script)
Client: True (MUST be checked)
Form button/Form Context Menu/Form Link: (UI Action must be one of these ‘Form’ types)
Onclick: -runClientCode();- (Points to the function in your script that should be run when the UI Action gets clicked)
Script:
//Client-side 'onclick' function
function runClientCode(){
if(<CONDITION_TO_VALIDATE> == false){
return false; //Abort submission
}
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), '<button_action_name>'); //MUST call the 'Action name' set in this UI Action
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if(typeof window == 'undefined')
runBusRuleCode();
//Server-side function
function runBusRuleCode(){
current.<field_name> = <value>;
current.update();
gs.addInfoMessage('You did it!');
action.setRedirectURL(current);
}
Refer the following link for mor:
https://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/
If it help mark helpful or correct
Thanks and regards
Anil