How to add button to the incident form under related links to recalculate few fields

Renu9
Tera Contributor

Hi All,

I am having business rules that calculates the following fields.

'Time to detect' and 'Time to diagnoise'

I need to add buttons in the incident form under related links to recalculate those fields. And I need to display those new buttons only to a particular assignment group. Please let me know how it can be done

5 REPLIES 5

OlaN
Giga Sage
Giga Sage

Hi,

What have you done so far, and where are you stuck?

To add a button or related link means to create a UI action that performs some script when clicked.

You can have a look at the existing OOB UI actions to get inspiration on how you should move forward.

Or you can read up on the Docs site to get started.

Namrata Ghorpad
Mega Sage
Mega Sage

Hello @Renu9 ,

Create UI action and select Form Button and in the condition write code like below

gs.getUser().isMemberOf('assignment group name');

and write the same code in UI action also that you have written in business rule.

 

Please mark my answer as helpful/correct if it helps you.

 

Regards,

Namrata

Hi @Namrata Ghorpad 

I have put the same code which was in BR to the UI Action script ,  I was trying to set the field value . It is working fine in BR but not in UI Action. I put the logs and noticed.

 var dif = "";
    if (current.alert_received == "yes") {     
        dif = gs.dateDiff(
            current.u_outage_time.getDisplayValue(),
            current.u_alert_received.getDisplayValue(),
            false);
        if (current.u_outage_time > current.u_alert_received) {
            dif =
                gs.dateDiff(
                    current.u_alert_received.getDisplayValue(),
                    current.u_outage_time.getDisplayValue(),
                    false);
        }
    }
    else {dif = gs.dateDiff(
            current.u_outage_time.getDisplayValue(),
            current.opened_at.getDisplayValue(),
            false);
        if (current.u_outage_time > current.opened_at) {
            dif =
                gs.dateDiff(
                    current.opened_at.getDisplayValue(),
                    current.u_outage_time.getDisplayValue(),
                    false);
        }
    }
    current.u_detect = dif;
    gs.log("time to detect " +current.u_detect);
 
The value is not being set in u_detect field

Hi,

Since the same code is going to be used in multiple places (both business rule, and UI action) I would suggest that you move the calculation to a script include method, and pass the dates to be calculated as inputs, and then return from the method, the result to be set in the field.

 

Also, I would recommend to use GlideDateTime methods instead of the gs.datediff method, because datediff only works in Global scope, not in scoped apps.

 

Let me know if you want additional help/suggestions to set this up.