Display Info /Error message in Project Workspace on planning Console on update of any field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2025 04:38 AM
Hi All,
I am trying to display a error message on change of any field on project task in below Planning View on Project Workspace but it is not coming using a Business Rule . It works fine in native end though. Please find the below screenshot:
Business Rule Script : On update --Table Name : Pm_project_task
Script :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @Attila Beregvar,
Here is the screenshot of the UI Policy triggers on Inicident record when Impact is 1
Run Script = true
Hope you understood..
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Hello Vinay, thanks for the quick reply!
I see that it works on a lets say "form" view of a record on a workspace - it does for me too with a project record the project workspace. The issue is that the project workspace has a specific page called "Planning" - which is not a regular form view, more like a planning console view - and the addInfoMessage/addErrorMessage functions are not working there
Thanks anyways!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Recommended Solution: Using Script Includes and Client Scripts (or Eventing)
The standard Business Rule functions for displaying messages (gs.addInfoMessage, gs.addErrorMessage) are designed for the classic ServiceNow UI (UI16). They do not automatically translate to the modern, component-based Workspace experience.
Here is the best practice approach for displaying real-time, server-side validation messages within the Project Workspace Planning Console:
1. Remove the Message Function from the Business Rule
Your current Business Rule is correctly running server-side, but the message function is the issue.
Business Rule (Server-Side):
Table: pm_project_task
When: on update
Action: Keep the Business Rule focused only on the data logic and validation check (e.g., setting a field value or validating if a condition is met).
Action: Remove the line gs.addInfoMessage('Test Message');.
2. Use a Script Include for Callable Validation
If your validation logic is complex, move it into an on-demand callable Script Include so the client-side script can access it. If the logic is simple, you can skip this step.
3. Implement a Client Script
The Planning Console relies on Client Scripts and the associated Workspace logic to display UI messages based on user interactions.
Client Script (Client-Side):
Table: pm_project_task
Type: onChange (on the specific field(s) you are monitoring) OR onSubmit (for broader form validation).
Script Logic:
Check the field value change (if onChange).
Call your Script Include (if necessary) via an AJAX call (GlideAjax) to perform the server-side validation check.
Based on the validation result:
Use the g_form.addInfoMessage(message) or g_form.addErrorMessage(message) functions. These are the correct client-side functions for displaying messages on the form within a Workspace context.
Note: The Planning Console is a complex component. For interactions directly within the grid view, you might need to investigate if the grid uses a specific Workspace Client Script or a Record Action configuration instead of a standard onChange client script. However, the use of g_form.addErrorMessage() after a validation check remains the standard method for displaying messages in the Workspace form view.
Certainly! Here is an effective example demonstrating how to implement server-side validation and display the error message on the Project Workspace Planning Console using a Client Script and a Script Include.
🛠️ Step-by-Step Implementation
1. Script Include (Server-Side Logic)
This script include contains the actual validation logic. It must be Client callable.
Name: ProjectTaskValidationUtil
API Name: x_yourscope_ProjectTaskValidationUtil (Use your actual Scope name if applicable, or use a global name like GlobalProjectTaskValidationUtil if in the Global scope).
Client callable: Checked (True)
Script:
JavaScriptvar ProjectTaskValidationUtil = Class.create(); ProjectTaskValidationUtil.prototype = { initialize: function() { }, // Method to check if the Planned Duration exceeds 5 days (example validation) validateDuration: function() { var duration = this.getParameter('sysparm_duration'); // duration in seconds var MAX_DURATION_SECONDS = 5 * 24 * 60 * 60; // 5 days in seconds var result = {}; // Check if the duration exceeds the maximum limit if (duration > MAX_DURATION_SECONDS) { result.isValid = false; result.message = "The Planned Duration cannot exceed 5 days for this type of task."; } else { result.isValid = true; } return JSON.stringify(result); }, type: 'ProjectTaskValidationUtil' };
2. Client Script (Client-Side Message Display)
This script runs on the client (browser) when the duration field changes, calls the server for validation, and displays the message if validation fails.
Name: Validate Planned Duration on Change
Table: pm_project_task
Type: onChange
Field name: duration
Applies to: Workspace
Script:
JavaScriptfunction onChange(control, oldValue, newValue, isLoading, isTemplate) { if (isLoading || newValue === '') { return; } // Clear previous error messages for this field g_form.hideFieldMsg('duration', true); // Instantiate GlideAjax and point to the Script Include var ga = new GlideAjax('ProjectTaskValidationUtil'); ga.addParam('sysparm_name', 'validateDuration'); ga.addParam('sysparm_duration', newValue); // Synchronous call is often necessary for onChange/onSubmit validation // to ensure the message is displayed before the save proceeds. ga.getXMLWait(); var answer = ga.getAnswer(); var result = JSON.parse(answer); if (!result.isValid) { // Display the error message using the Workspace client-side function g_form.addErrorMessage(result.message); // Additionally, you can highlight the field with a specific error message g_form.showFieldMsg('duration', result.message, 'error'); // Optional: Revert the field value if necessary (only if this prevents saving) // g_form.setValue('duration', oldValue); } }Key Takeaways for Workspace Solutions
The effective solution follows the principle of separation of concerns:
Business Rule is not used for displaying UI messages.
The Script Include performs the necessary server-side data validation.
The Client Script is responsible for monitoring user input and displaying the message using the correct client-side function (g_form.addErrorMessage()), which is respected by the Project Workspace UI framework.
This approach is the most effective and supportable way to handle validation messages in modern ServiceNow Workspaces like SPM's Planning Console.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Thanks for the detailed answer! The generic approach you described should be correct in theory, but this is the problem exactly: the client side g_form.addInfoMessage / addErrorMessage is not working on the Planning tab of the project workspace. It doesn't matter where you iniate it from (client script, UI policy script, else), the message does not appear.
Is it working for you?
Thanks,
Attila
