A Scripting Guide For Master Data CRUD Operations in SAP Analytics Cloud Stories
2023-12-24 23:28:18 Author: blogs.sap.com(查看原文) 阅读量:13 收藏

SAP Analytics Cloud is an extremely useful business tool for data analysis. It consists of various components, each with individual features to facilitate analysis. In the realm of data analysis, we employ stories and analytical applications. Today, we will focus on understanding how to create, read, update, and delete (CRUD) with model master data using Planning Model scripting

There is four main functions for Planning Model Scripting Object

Note: Planning Model Script Object only supports Generic dimensions, its not support date, version, account and organization dimensions.

Before staring scripting, you need to create Planning Model Script Object, Follow this blog to know how to create Planning Model step by step.

Video is also available with full guidance step by step

1. Create Member

For creating new master data in model, we have to use createMembers function.

  • Parameters:
    1. dimensionId (Type: string)
      • Represents the ID of the dimension for which the members will be updated.
    2. members (Type: PlanningModelMember JSON | PlanningModelMember[] JSON)
      • Represents the member or an array of members in JSON format that contain the updated information.
  • Return Type:
    • boolean
      • The function is expected to return true if the update operation was successful, and false otherwise.
  1. Variable Declaration:
    var dimensionId = "CARS";

    This line declares a variable dimensionId and assigns it the value “CARS.” This variable represents the ID of the dimension where the new member will be created.

  2. Member Object Definition:
    members = {
    	id:"Audi",
    	description:"Audi Car",
    	properties:{
    		car_model:"A4"
    	}
    };
  3. Create variable with name ‘members‘ as Script Variable with data type of PlanningModelMember
  4. The members object is defined with properties for the new member. It has an ID (“Audi”), a description (“Audi Car”), and additional properties, such as “car_model” with a value of “A4.”
  5. Function Call to Create Members:
    PlanningModel_1.createMembers(dimensionId, members);

    This line calls the createMembers function of the PlanningModel_1 object, passing the dimensionId and members as parameters. This function is responsible for creating planning model members. If the operation is successful, it typically returns true; otherwise, it returns false.

Result:-

2. Get Member

  • Parameters:
    1. dimensionId (Type: string)
      • Represents the ID of the dimension from which the member will be retrieved.
    2. memberId (Type: string)
      • Represents the ID of the specific member to be retrieved.
  • Return Type:
    • PlanningModelMember
      • The function is expected to return an object of type PlanningModelMember, which likely contains information about the specified planning model member.

Here’s how you might use this function in a practical example:

/* Get single master data */

var dimensionId = "CARS";
var memberId = "Audi";

var member = PlanningModel_1.getMember(dimensionId, memberId);

// Now 'member' contains information about the specified planning model member.
// You can access properties of the member object as needed.

/* Get all master data */

var all_members = PlanningModel_1.getMembers(dimensionId);

//Now 'all_members' contains information about the all planning model member.

In this example, the function is called with a specific dimensionId (“CARS”) and memberId (“Audi”). The returned member object likely contains details such as the member’s ID, description, and other relevant properties specific to the planning model in SAP Analytics Cloud.

//Output of member variable
{
    "id": "Audi",
    "description": "Audi Car",
    "properties": {
        "car_model": "A4"
    },
    "hierarchies": {}
}

//Output of all_members varibale
[
    {
        "id": "#",
        "description": "Unassigned",
        "properties": {
            "car_model": ""
        },
        "hierarchies": {}
    },
    {
        "id": "Audi",
        "description": "Audi Car",
        "properties": {
            "car_model": "A4"
        },
        "hierarchies": {}
    },
    {
        "id": "Bugatti",
        "description": "Bugatti Chiron",
        "properties": {
            "car_model": "Sport 110 Ans"
        },
        "hierarchies": {}
    }
]

3. Update Member

  • Parameters:
    1. dimensionId (Type: string)
      • Represents the ID of the dimension for which the members will be updated.
    2. members (Type: PlanningModelMember JSON | PlanningModelMember[] JSON)
      • Represents the member or an array of members in JSON format that contain the updated information.
  • Return Type:
    • boolean
      • The function is expected to return true if the update operation was successful, and false otherwise.
  • Note:
    • After performing the update, it is recommended to call certain refresh methods (DataSource.refreshData() or Application.refreshData()) to ensure that charts or tables reflect the updated members in subsequent operations.
  • Create variable with name ‘members‘ as Script Variable with data type of PlanningModelMember

Here’s how you might use this function in a practical example:

var dimensionId = "CARS";
members = {
        id: "Audi",
        description: "Audi New Car",
        properties: {
            car_model: "Q3"
        }
    };

var isUpdateSuccessful = PlanningModel_1.updateMembers(dimensionId, members);

// Now 'isUpdateSuccessful' indicates whether the update operation was successful.
// You can handle further logic based on this result.

In this example, the function is called with a specific dimensionId (“CARS”) and an data of memebers. The returned isUpdateSuccessful variable indicates whether the update operation was successful.

4. Delete Member

  • Parameters:
    1. dimensionId (Type: string)
      • Represents the ID of the dimension for which the members will be deleted.
    2. members (Type: string | string[])
      • Represents the ID of the member or an array of member IDs to be deleted.
  • Return Type:
    • boolean
      • The function is expected to return true if the delete operation was successful, and false otherwise.
  • Note:
    • After performing the delete, it is recommended to call certain refresh methods (DataSource.refreshData() or Application.refreshData()) to ensure that charts or tables reflect the deleted members in subsequent operations.

Here’s how you might use this function in a practical example:

var dimensionId = "CARS";
var membersToDelete = ["Audi"]; //or "Audi"

//if you want to delete multiple data just pass as array ex ["Audi","BMW"....]
var isDeleteSuccessful = PlanningModel_1.deleteMembers(dimensionId, membersToDelete);

// Now 'isDeleteSuccessful' indicates whether the delete operation was successful.
// You can handle further logic based on this result.

Conclusion

In this blog post, we explored the powerful capabilities of SAP Analytics Cloud for data analysis, focusing on the manipulation of planning model members through CRUD operations. We learned how to create, read, update, and delete members using scripting functions such as createMembers, getMember, updateMembers, and deleteMembers.

These operations provide a flexible framework for managing data within specific dimensions, offering a seamless experience for users leveraging SAP Analytics Cloud. Whether you are adding new members, retrieving information, updating existing data, or removing members, the scripting functionalities enable efficient interaction with planning models.


文章来源: https://blogs.sap.com/2023/12/24/a-scripting-guide-for-master-data-crud-operations-in-sap-analytics-cloud-stories/
如有侵权请联系:admin#unsafe.sh