Servicely Administration
Scripting
UI Event
5 min
a ui event automates business logics on a servicely table’s form and/or fields as they are loaded or as you interact with them on your web browser, i e doing field updates or saving your changes on the form it runs on the client side (your computer’s web browser) it can call system controllers docid pfjtclem zcu8ktp8zjw to run server side functions (also refer to table api (server) docid\ latfchaaxu1wqcrr1vn0p ) it has access to the current record displayed on the form it has access to classes and functions within client accessible application properties (refer to application properties docid\ ltoo4wlb8le r0q20fndx ) javascript knowledge is required creating a ui event field name field type description sample value name string name of the ui event for administrative purposes incident set requested for based on selected requestor event type choice whether the ui event is to run based on a field or a form field event form event field event event name choice action taking place that should result in this ui event run if event type is “field event”, the valid events to choose from are on change < runs when form is loading or when nominated field on ui event changes its value > on relation update < runs when a related list is updated with entries added or removed > if event type is “form event”, the valid events to choose from are on form load < runs when a form has finished loading > on form submit < runs after you submit changes on the form by pressing the save button > only for “on form submit”, your script can return either true or false to decide whether or not to allow the form’s submission (create or update of a record) to proceed on change active boolean when active, the ui event will be available to run should it meets the configured events yes table reference table the ui event applies to incident field reference available if event type is “field event” the ui event runs when the field’s value on the form has been updated requestor application reference application that the ui event is packaged under itsm description string provides more details about what the ui event is for, for administrative purposes when a requestor is set on an incident, copy them across as an incident’s requested for if it isn’t set already script script client side script the ui event runs the script has access to the “current” object that represents the current record the “viewaspect” variable the represents the view aspect shown on the form the ui event runs on please refer to aspect configuration for more information about view aspects the “isloading” variable that returns true when the form is loading for “on form submit” event provide a return false; if you need to prevent a form’s submission not providing a return value is the same as providing a return true; statement examples make assignee required only when status is not new for a viewaspect called “servicedesk” field value name incident always for servicedesk aspect event type form event event name on form load active yes table incident description when viewaspect is “service desk” and status is not new, always set the assignee to be required otherwise keep optional keep hidden for all other aspects script default an incident’s location based on requestor’s location data, using a controller this requires the use of a controller as we need to query an incident’s requestor user record and get their location field value name incident default location based on requestor event type field event event name on change active yes table incident field requestor description once a requestor is selected/updated, if an incident’s location is blank, set the location based on that user record script refer to below for sample of the controller controller “userinfocontroller” script referenced in the ui event’s script in above example, can look like the following (variable “locationid” is what the controller returns and the ui event makes use of) answer = {}; // query the user table for the record with the provided userid parameter if (userid) { let userrec = table("user", userid); if (userrec) { if (userrec location hasvalue()) { answer locationid = userrec location value(); } } } answer; default an incident’s location based on requestor’s location data, using a rest call the ui event can be configured the same way per the above example with a controller, but the ui event script should look like the following instead //assuming there is a requestor, form is not loading, location is not already set if (!isloading && current requestor hasvalue() && !current location hasvalue()) { rest get("user", current requestor(), { fields "location" }) then(response => { current location(response data location); }); }