Get Dirty Data Status

The Get Dirty Data Status action is used to check if any of the values have changed for the tracked variables within a particular scope (application, page, fragment, layout, flow), within any contained pages, fragments, layouts, or flows, or within any extensions of them. If the value of one of the tracked values changes, the Dirty Data status for the variable's scope changes from 'notDirty' to 'dirty'. The Dirty Data status is returned for the scope that this action is used in.

This action has no parameters to set. Also, this functionality works with all of the data types, except Service Data Providers (SDPs). Currently, you'll have to handle the tracking of value changes for SDPs.

To set a variable to be tracked for value changes, go to the relevant Variables tab, select the variable, and in the Properties pane, set its Dirty Data Behavior property to 'Track'.

To reset the scope's Dirty Data status back to 'notDirty', use the Rest Dirty Status action.

Here's a sample action chain that uses this action, which is started by a vbBeforeExit event listener for the page:

    async run(context) {
      const { $page, $flow, $application } = context;
      
      const getDirtyDataStatusResult = await Actions.getDirtyDataStatus(context, {
      });

      if (getDirtyDataStatusResult.status === 'dirty') {
        // Warn the user if there are unsaved changes
        await Actions.fireNotificationEvent(context, {
          summary: 'You have unsaved changed. Please Save or Cancel',
          displayMode: 'transient',
          type: 'error',
        });

        // Stay on the page
        return { cancelled: true };
      }

      /* Navigation from this page can be canceled by returning an object with the property cancelled set to true. 
        This is useful when the page state is dirty and navigation should not be allowed before saving.*/
        return { cancelled: false };
    }