Technology Blog Posts by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Sebastian_Gesiarz
Active Participant
1,705

As an SAC Planning Developer, you might need to run some custom code or Data Actions before or right after the user clicks the Publish Data button. I would like to highlight two possible solutions for this use case:

  1. If your Story is relatively small and simple, and you are willing to sacrifice the official "Publish Data" button, you can remove it by going to the View Time Settings and removing it from the Toolbar. Once you have done this, you can add a custom publish button with your coding to each of the Story Pages. It's not ideal, but it works.
    SebastianGesiarz_0-1721999075498.png
    SebastianGesiarz_1-1721999127175.png
  2. The second semi-automated option would be to execute your coding after the user hits the official Publish Data button or publishes a Private Version to the Public one.
    Handling Revert Data button: A challenge is that if the user clicks the 'Publish Data' -> 'Revert Data' button, it will also trigger the script. This is because both actions - publishing and reverting - result in a clean version after having unpublished data. Therefore, it is not possible to distinguish between Publish and Revert in this context.

Now I would like to focus on the solution for the second point. It needs to be implemented in each of the tabs used for planning separately. The upside is that the user does not have to click anything. To achieve this, you can check if there are any private versions in the onInitialization event of the page and save them for future use.

 

 

 

// Save private versions
var privateVersions = TabCostCalc.getPlanning().getPrivateVersions();

// Get private version IDs
for (var l = 0; l < privateVersions.length; l++) {
   	strArrPrivateVersionCc.push(privateVersions[l].getId());
}

 

 

 

Now you need to check on every table refresh if the private version existed before and disappeared. You can implement this in the onResultChanged event. Additionally, you need to add a check if the official version was in a 'dirty' state and started being clean. This would indicate that someone either has reverted the changes or published them.

 

 

 

var activeVersionMembers = icVersion.getInputControlDataSource().getActiveSelectedMembers();
var userPrivateVersions = YourTableId.getPlanning().getPrivateVersions();
var executingCustomLogicMessage = "Hang tight! We're executing custom logic.";

if (activeVersionMembers.length > 0) {
    var publicPlanVersion = YourTableId.getPlanning().getPublicVersion(activeVersionMembers[0].description);
}

if (privateVersionArray.length > 0) {
    var privateVersionIds = ArrayUtils.create(Type.string);

    // Collect private version IDs
    for (var i = 0; i < userPrivateVersions.length; i++) {
        privateVersionIds.push(userPrivateVersions[i].getId());
    }

    // Verify if any private versions have been removed
    for (var j = 0; j < privateVersionArray.length; j++) {
        var missingVersions = ArrayUtils.create(Type.string);
        var existingVersions = ArrayUtils.create(Type.string);

        if (!privateVersionArray.includes(privateVersionIds[j])) {
            missingVersions.push(privateVersionIds[j]);
            Application.showMessage(ApplicationMessageType.Info, "Version " + privateVersionArray[j] + " was published or removed.");
            Application.showBusyIndicator(executingCustomLogicMessage);

            // Add your code here to execute after a private version has been published to public

        } else {
            existingVersions.push(privateVersionArray[j]);
        }
    }

    // Refresh private version IDs
    while (privateVersionArray.length > 0) {
        privateVersionArray.pop();
    }
    for (var k = 0; k < userPrivateVersions.length; k++) {
        privateVersionArray.push(userPrivateVersions[k].getId());
    }
}

if (publicPlanVersion) {
    if (publicPlanVersion.isDirty()) {
        isVersionDirty = true;
        // Notify the user that they may need to publish their data
        PublishText.setVisible(true);
    } else if (isVersionDirty) {
        if (!publicPlanVersion.isDirty()) {
            Application.showBusyIndicator(executingCustomLogicMessage);

            // Add your code here to execute after the results have been published and the version is no longer "dirty"

            // Reset the indicator for private versions after publishing results
            isVersionDirty = false;
            PublishText.setVisible(false);
        }
    }
}

 

 

 

An example scenario in which this option could prove useful is in case you would like to materialize your data for analytics after each publication of the planning values.