Ui Action and Ui Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2023 01:41 AM
what is Ui Action and Ui Script in ServiceNow.
please explain with a practical example.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2023 01:45 AM
In ServiceNow, Ui Actions and Ui Scripts are used to customize the user interface and enhance functionality.
1. Ui Actions:
- Definition: Ui Actions are rules that define custom actions or buttons on forms and lists.
- Purpose: They provide a way to extend and customize forms and lists by adding buttons, context menu items, or other UI elements that perform specific actions when clicked.
- Practical Example: Let's say you want to add a button on an incident form that allows users to escalate the priority of the incident. You would create a Ui Action that triggers a script to update the priority field when the button is clicked.
2. Ui Scripts:
- Definition: Ui Scripts are scripts that run on the client-side (in the user's browser) to modify the behavior or appearance of forms or lists.
- Purpose: They are used to implement client-side logic, validations, calculations, or UI customizations.
- Practical Example: Suppose you want to validate that the "Due Date" field on a task form is not in the past when a user submits the form. You would write a Ui Script to check the date and display an error message if it's invalid.
Practical Example:
Let's say you want to create a Ui Action and Ui Script in ServiceNow to mark a task as complete with a single click.
1. Ui Action:
- Name: Mark as Complete
- Table: Task
- Active: Checked
- Show Insert: Checked
- Client: Checked
- Onclick Script:
javascript
var gr = new GlideRecord('task');
gr.get(current.sys_id);
gr.setValue('state', 3); // 3 represents "Closed Complete" state
gr.update();
gs.addInfoMessage('Task marked as complete.');
action.setRedirectURL(current);
2. Ui Script:
- Name: Validate Due Date
- Table: Task
- Type: Client Script
- Script:
javascript
function onSubmit() {
var dueDate = g_form.getValue('due_date');
var today = new Date();
if (new Date(dueDate) < today) {
alert('Due Date cannot be in the past!');
return false; // Prevent form submission
}
return true; // Allow form submission
}
In this example, the Ui Action creates a button named "Mark as Complete" on the Task form. When clicked, it changes the task's state to "Closed Complete". The Ui Script ensures that the Due Date is not in the past when the user submits the form.
These are simplified examples, and in real-world scenarios, you may need to consider additional factors like access control, error handling, and more complex business logic.
Mark correct or helpful if applicable.
Thanks & Regards,
Sayali Gurav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2023 01:55 AM - edited 10-10-2023 01:57 AM
Hi @showsid02 ,
Certainly! Let's break down what UI Actions and UI Scripts are in ServiceNow with practical examples:
### **UI Actions:**
A UI Action in ServiceNow is a configurable action that can be added to forms, lists, or related lists. It allows users to perform specific operations, such as creating a new record, updating an existing record, or navigating to a different page. UI Actions can be defined for a particular table and can be displayed conditionally based on certain criteria.
**Example Scenario:** Let's consider a Task table where you want to add a button called "Mark as Complete" that allows users to mark a task as complete.
1. **Create a UI Action:**
- **Name:** Mark as Complete
- **Table:** Task
- **Type:** Button
- **Script:**
current.state = '3'; // Set the state to 'Complete'
current.update();
2. **Usage:** When users open a task record, they will see the "Mark as Complete" button. Clicking this button will change the task's state to "Complete."
### **UI Scripts:**
A UI Script in ServiceNow is a JavaScript script that can be used to modify the behavior or appearance of forms, lists, or other UI elements without making changes to the underlying data model. UI Scripts run in the context of the client's web browser and can enhance the user interface dynamically.
**Example Scenario:** Let's consider you want to display a pop-up message when a user opens an incident form.
1. **Create a UI Script:**
- **Name:** Show Pop-up Message
- **Table:** Incident (or leave it empty for global scope)
- **Script:**
alert('Welcome to the Incident Form!'); // Display a pop-up message
2. **Usage:** When users open an incident form, they will see a pop-up message saying "Welcome to the Incident Form!"
**Key Differences:**
- **UI Actions** are used for defining specific actions users can take on records (e.g., buttons for specific operations).
- **UI Scripts** are used for enhancing the user interface by adding dynamic behavior or manipulating UI elements (e.g., displaying pop-up messages, changing field behavior).
Both UI Actions and UI Scripts are powerful tools in ServiceNow that enable you to create a more customized and user-friendly experience within the platform.
Mark my answer as helpful & accepted if it helps you resolve your query.
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2023 02:43 AM
In ServiceNow, UI Actions and UI Scripts are two key components that allow you to customize and extend the user interface and functionality of the platform.
Let's break down each of these components with practical examples:
UI Action: A UI Action is a way to add buttons, context menu items, or links to forms and lists in ServiceNow. UI Actions are typically used to perform specific actions when interacting with records or lists. They can be triggered by users, either from a form or a list, and can be used to automate common tasks, create new records, or navigate to related information.
Practical Example of UI Action: Let's say you have an incident record in ServiceNow, and you want to create a UI Action that allows you to assign the incident to a specific user with a single click.
Create a UI Action:
- Navigate to "System Definition" > "UI Actions" in ServiceNow.
- Click "New" to create a new UI Action.
- Define the action's properties, such as the name, table, and the script that will be executed when the action is triggered.
- In the script, you can use GlideRecord operations to set the assignment group and assignee fields of the incident record.
Add the UI Action to the Form or List:
- After creating the UI Action, you can choose to add it to the incident form or list.
- On the form, you can place it as a button above the form fields.
- On the list, you can make it available as an action in the context menu for incident records.
Test the UI Action:
- Now, when you open an incident record or a list of incidents, you'll see the UI Action you created.
- Clicking on it will trigger the script you defined, which can perform the desired action, such as assigning the incident to a user.
UI Script: A UI Script is a JavaScript script that runs on the client side (in the user's web browser) to modify the behavior or appearance of forms and lists in ServiceNow. UI Scripts are used for client-side scripting and can be applied to specific forms, list views, or globally across the platform.
Practical Example of UI Script: Let's say you want to enhance the incident form by adding client-side validation to ensure that a user selects a priority level when creating or updating an incident.
- Create a UI Script:
- Navigate to "System Definition" > "UI Scripts" in ServiceNow.
- Click "New" to create a new UI Script.
- Write JavaScript code that checks whether the priority field is empty when the user submits the form. If it's empty, display an error message.
Apply the UI Script to the Form:
- In the UI Script record, you can specify where the script should be applied. For example, you can apply it to the incident form.
- Specify the condition under which the script should run, such as on a particular table or when certain fields are present.
Test the UI Script:
- When a user tries to submit an incident form without selecting a priority, the UI Script will trigger and display the error message, preventing the form submission until a priority is selected.
UI Actions and UI Scripts are powerful tools in ServiceNow that allow you to customize and enhance the user experience by adding actions, validations, and other client-side functionality to your forms and lists.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards
Sharan