Use publish API on Versions

As an application designer or story developer, you can use the publish API for publishing public or private versions.

Before You Start

Before using the publish API, make sure that you've checked the following:
  • You've created an application or optimized story that contains a table and SAP Analytics Cloud planning model.

  • You've assigned the planning model to the table.

  • You've made up your mind on how to visualize or expose the publish API to the end users. For example, you may want them to click on a button to publish a version.

  • If users try to publish a version that exceeds the resource limits and there're not enough resources available in the system for the publishing operation, they'll see a corresponding message.

Examples for Publishing Public Versions

The following example shows how you can use the publish API for publishing the public version Actual:
Sample Code
var actualVersion = Table_1.getPlanning().getPublicVersion("Actual");
if (actualVersion) {
    if(actualVersion.isDirty()) {
        actualVersion.publish();
    };
};
The following example shows how you can use the publish API for publishing all public versions:
Sample Code
var publicVersions = Table_1.getPlanning().getPublicVersions();
for (var j = 0; j < publicVersions.length; j++) {
    if (publicVersions[j].isDirty()){
        publicVersions[j].publish();
    };
};

Examples for Publishing Private Versions

You can use the publish API for private versions in two different ways:
  1. No parameters are specified. In this case, the original version from which the private version was created is overwritten.
    Sample Code
    // override the original version from which myActual was created
    var myActualVersion = Table_1.getPlanning().getPrivateVersion("myActual");
    if (myActualVersion) {
        myActualVersion.publish();
    };
    
  2. The target version is specified. You can further specify the default behavior for publishing a private version to an unrelated public version by the parameter updateChangedDataOnly. If it's false, the entire private version overwrites the public target version. If it's true, only the changed data is published to the public target version.
    Sample Code
    // override the forecast version with myActual and update only changed data
    var myActualVersion = Table_1.getPlanning().getPrivateVersion("myActual");
    var forecastVersion = Table_1.getPlanning().getPublicVersion("Forecast");
    if (myActualVersion && forecastVersion) {
        myActualVersion.publish(forecastVersion, true);
    };