Close event on closure of 'custom workspace' tab

Prabhjot Kaur4
Tera Contributor

Hi All,

 

In custom workspace , can the form gets saved on closure of workspace tab.

My requirement is to capture/save the time  if user is only viewing the ticket form and has not done any changes.

On load of the ticket, when form is opening I am able to capture the time. But on closure of form, if no changes has done on ticket then am not able to save that time.

 

I am thinking to achieve this with the help of events. But not sure what event gets triggered on closure of workspace tab and if I get event how to handle that event as well.

 

Please help here.

 

Thanks

Prabh

2 REPLIES 2

Rahul Kumar17
Tera Guru

Hi,

In a custom workspace, capturing and saving the time when a user is viewing a ticket form and hasn't made any changes can be achieved using events. Unfortunately, there isn't a specific event triggered on the closure of a workspace tab. However, you can utilize a combination of events and other techniques to accomplish your requirement. Here's a suggested approach:

  1. On form load: As you mentioned, you are already capturing the time on form load. Make sure you store this time in a variable or a field for later comparison.

  2. Track changes: You need to track any changes made by the user to determine if the form has been modified. You can achieve this by utilizing the onchange event or specific field-level events to monitor any modifications to form fields. When a change is detected, you can set a flag or update a field value to indicate that changes have been made.

  3. On form closure: In the absence of a dedicated closure event, you can employ alternative approaches to capture the closure of the form or workspace tab. Some options include:

    a. Utilize the beforeunload event: This event is triggered when the user attempts to leave or close the tab. You can bind a listener to this event and prompt the user to confirm their intention to close the form. In the event of closure, you can save the current time if no changes have been made based on the flag or field value you set during the tracking of changes.

    b. Periodically check form status: Implement a timer or interval function to periodically check the form's status. If the form or workspace tab is no longer active, you can consider it as a closure and save the time if no changes have been made.

  4. Save the captured time: When you determine that the form closure has occurred without any modifications, you can save the captured time to the appropriate field or variable.

It's worth noting that the beforeunload event and periodic status checks have limitations due to browser restrictions and potential inconsistencies. It's recommended to test these approaches thoroughly across different browsers to ensure consistent behavior.

By combining the above techniques, you can capture and save the time when a user is viewing a ticket form and hasn't made any changes, even though there isn't a specific event triggered on workspace tab closure.

 

Thanks,

Rahul Kumar

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar

Prabhjot Kaur4
Tera Contributor

Hi Rahul

 

Many thanks for your reply !

 

I am stuck here .. how to use beforeunload event in UI builder on record page.

Can you please guide me.

 

Thanks

Prabh