Client script to show alert when incident active is true

BiancaK
Tera Expert

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?

function onLoad() {
    //Type appropriate comment here, and begin script below
    var category = g_form.getValue('category');
    var subCategory = g_form.getValue('subcategory');
     
    if (category == 'A' && subCategory == 'Y')  {
        g_form.addInfoMessage("Test message 1");
    } else if (category == 'ZZ' && subCategory == 'YY')  {
        g_form.addInfoMessage("Test message 2");
        
    }
}
1 ACCEPTED SOLUTION

@BiancaK 

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
}

 

 

View solution in original post

12 REPLIES 12

@BiancaK Is your active field on form? I mean visible on form. If not try bringing on form and then try

no the active field is not meant to be on the form. 
However, when I do bring it on the form the g_form.getValue('active'); works 

But how do I achieve this requirement without having the active field on the form?

@BiancaK 

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
}

 

 

Hi @Satishkumar B 

Please share the screenshot of your BR?

Thanks

@BiancaK 

SatishkumarB_0-1724323587068.png