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 viewers. For example, you 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);
    };
    

APIs to Resolve Publish Conflicts

You can specify the parameter in the publish API to let viewers resolve changes in conflict with another viewer's when publishing a version.

Note

The API works whether Display options to resolve version with publish conflicts is enabled or not in the system configuration.

For publishing public versions, you can choose to show the warning dialog for viewers to resolve conflicting changes, directly publish the version with conflicting changes overwritten by another viewer without showing the dialog, or revert the version without showing the dialog:
//option 1: Shows the warning dialog for viewers to resolve conflicting changes.
{ publicPublishConflict: PublicPublishConflict.ShowWarning }

//option 2: Publishes the version with conflicting changes overwritten by another viewer without showing the conflict warning dialog.
{ publicPublishConflict: PublicPublishConflict.PublishWithoutWarning }

//option 3: Reverts the version without showing the conflict warning dialog.
{ publicPublishConflict: PublicPublishConflict.RevertWithoutWarning }

For publishing private versions, you can choose to either show the warning dialog for viewers to resolve conflicting changes, or directly publish the version with conflicting changes overwritten by another user without showing the dialog:

//option 1: Shows the warning dialog for viewers to resolve conflicting changes.
{ privatePublishConflict:PrivatePublishConflict.ShowWarning }

//option 2: Publishes the version with conflicting changes overwritten by another viewer without showing the conflict warning dialog.
{ privatePublishConflict:PrivatePublishConflict.PublishWithoutWarning }