Scenario Based Question
Q1: How to generate / trigger notifications using a UI Action?
💡 Answer: You can achieve this in three easy steps:
- 1️⃣ Create an Event.
- 2️⃣ Create a Notification as per your requirement and use the created event as the trigger.
- 3️⃣ Create a UI Action which fires your event with a single line of code:
gs.eventQueue('event_name', null, parm1, parm2);
💡 Pro Tip: Ensure your UI Action is set to run on the correct table and condition to avoid unnecessary triggers.
💡 Q2: If we set the priority as 1
on a Client Script and 2
on a Business Rule, what value will be saved in the table?
✅ Answer:
This depends on the execution order and how ServiceNow handles data persistence between client-side and server-side logic.
📜 Execution Order:
- Business Rules typically execute on the server before data is committed to the database.
- Client Scripts run in the browser on the user’s machine, and their changes only reach the server when the form is submitted.
💾 Data Persistence:
- When a Business Rule sets a field value, it directly updates the record in the database before saving.
- Client Scripts only manipulate form data on the client side. Unless explicitly sent and not overridden by server logic, these changes may not persist.
🔍 Example Flow:
- 1️⃣ Business Rule sets
Priority = 2
. - 2️⃣ Client Script tries to set
Priority = 1
. - 3️⃣ During save, the server-side Business Rule logic overrides the client-side change.
📌 Final Outcome: The record will save with Priority = 2
because server-side Business Rule execution has the final say before the database commit.
Tip: If you want the client-side value to persist, ensure server-side logic does not overwrite it, or adjust the order and conditions in your Business Rules.