Use copy API on Versions

As an application designer or story developer, you can use the PlanningVersion.copy API for creating a private version from an existing version. This function only works for SAP Analytics Cloud models.

Before You Start

Before using the copy 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 copy API to the end users. For example, you may want them to click on a button to copy a version.

  • If a planning area is to be copied, make sure that a recommended planning area has been defined for the model.

  • If users try to copy a version that exceeds the resource limits and there aren't enough resources available in the system for the copying operation, they'll see a corresponding message.

Note

All versions are copied with the default currency conversion, which can't be changed.

Script API and Examples

You can use the following API to copy and create versions:
Code Syntax
copy(newVersionName: string, planningCopyOption: PlanningCopyOption, versionCategory?: PlanningCategory, planningAreaFilters?: PlanningAreaFilters): boolean
You can specify the area to be copied via the parameter planningCopyOption:
  • AllData: All data is included when the version is copied.

    The following script copies all data from a private version to create a private one in budget category:
    Sample Code
    var originalVersion = Table_1.getPlanning().getPrivateVersion("privateVersionToCopy");
    if (originalVersion) {
        originalVersion.copy("targetVersionName", PlanningCopyOption.AllData, PlanningCategory.Budget)
    };
  • NoData: No data is included when the version is copied.

    The following script creates a blank version from a public one without changing the category:
    Sample Code
    var originalVersion = Table_1.getPlanning().getPublicVersion("publicVersionToCopy");
    if (originalVersion) {
        originalVersion.copy("targetVersionName", PlanningCopyOption.NoData)
    };
  • PlanningArea: Only data in the planning area is included when the version is copied.

    The following script copies the data in planning area from a public version to create a private one with a unique name:
    Sample Code
    var originalVersion = Table_1.getPlanning().getPublicVersion("publicVersionToCopy");
    if (originalVersion) {
        originalVersion.copy("Version"+ Date.now().toString(), PlanningCopyOption.PlanningArea));
    }
    The following script copies the data in planning area from a private version to create one with a unique name in forecast category:
    Sample Code
    var originalVersion = Table_1.getPlanning().getPrivateVersion("privateVersionToCopy");
    if (originalVersion) {
        originalVersion.copy("Version"+ Date.now().toString(), PlanningCopyOption.PlanningArea, PlanningCategory.Forecast));
    }
  • VisibleData: Only data in the viewport is included when the version is copied.
  • CustomizedPlanningArea: Only data in the customized planning area is included when the version is copied. You need to specify the dimensions and members that construct the planning area via PlanningAreaFilters, which is mandatory in this case.

    The following script applies filters and then copies the data in the customized planning area from an actual version to create another one:

    Sample Code
    var PlanningAreaFilters = Table_1.getPlanning().getPlanningAreaInfo();
    
    // Remove predefined Date dimension filter
    PlanningAreaFilters.removeFilter("Date");
    
    // Change predefined filter.
    PlanningAreaFilters.changeFilter("GenericDimension", {"hierarchy":"H1","members":["[ GenericDimension].[H1].&[A]"]});
    
    // Assign filter
    var filters = PlanningAreaFilters.getFilters();
    
    // Copy version with CustomizedPlanningArea option and filters
    Table_1.getPlanning().getPublicVersion("Actual").copy("Actual2", planningPublicEditOption.CustomizedPlanningArea, undefined, filters )