- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 02:56 AM
Good Day
I am trying to achieve the below. When an agent opens an incident record and the category=x and subcategory=y and incident is active then show an alert.
But if the category=x and subcategory=y and incident is NOT active then do not show an alert.
How do I check if the incident record is active in an onLoad client side script?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 03:22 AM
1. Create a Display Business Rule:
This will pass the active status to the client-side using g_scratchpad.
(function executeRule(current, g_scratchpad) {
g_scratchpad.isActive = current.active; // Pass the active status to the client
})(current, g_scratchpad);
2. Modify Your Client Script:
Use the g_scratchpad to check the active status.
function onLoad() {
// Get the values of category, subcategory, and active status
var category = g_form.getValue('category');
var subCategory = g_form.getValue('subcategory');
var isActive = g_scratchpad.isActive; // Get the active status from g_scratchpad
// Check if the category and subcategory match, and if the incident is active
if (category == 'A' && subCategory == 'Y' && isActive) {
alert("Test message 1: Incident is active.");
} else if (category == 'ZZ' && subCategory == 'YY' && isActive) {
alert("Test message 2: Incident is active.");
}
// If the incident is not active, no message will be displayed
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 03:01 AM
Hi @BiancaK
Did you try with UI policy and add error / info in script.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 03:03 AM
How do I achieve it with client script perhaps? because when I use g_form.getValue('active'); it does not work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 03:03 AM
@BiancaK Try this:
function onLoad() {
// Get the values of category, subcategory, and active status
var category = g_form.getValue('category');
var subCategory = g_form.getValue('subcategory');
var isActive = g_form.getValue('active'); // This gets the active status of the incident
// Check if the category and subcategory match, and if the incident is active
if (category == 'A' && subCategory == 'Y' && isActive == 'true') {
alert("Test message 1: Incident is active.");
} else if (category == 'ZZ' && subCategory == 'YY' && isActive == 'true') {
alert("Test message 2: Incident is active.");
}
// If the incident is not active, no message will be displayed
}
please mark my response as helpful 👍and accept the solution✅ if it helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 03:04 AM
Hi
Yes I have tried this to get the value of the active field and it does not work.