How to add button to the incident form under related links to recalculate few fields
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-26-2023 03:05 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-26-2023 03:57 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-26-2023 03:58 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-26-2023 08:23 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-26-2023 11:34 AM
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.