cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SAP SAC Data Action/Scripting - create new member and copy measures from one row to another

iksuuu
Explorer
0 Likes
1,316

Hi All,

In a SAC planning model, l want to first choose a contract , then create a new member based on this contract for a dimension(planning number), and then copy all measures value of this contract to the rows, with contract and planning number.

Example:

Before duplication:

Contract NumberPlanning NumberPosition VersionDate PriceQuantity
2025-1Actual2025-04-011001000
2025-2Actual2025-05-012002000

After clicking the button:

Contract NumberPlanning NumberPosition VersionDate PriceQuantity
2025-1Actual2025-04-011001000
2025-2Actual2025-05-012002000
20252025_0011Planning2025-04-011001000
20252025_0012Planning2025-05-012002000

Goal:
When a user select a contract and then clicks a **button**, I want to:
1. Copy all rows for the selected contract (`Contract Number`).
2. Generate a new `Planning Number` using the format: `ContractNumber_0001`, incrementing for each new copy.
3. Set the `Version` to "Planung".
4. Add these new rows back into the dataset.

Questions:
1. How can I implement this row duplication logic in SAC?
2. Can this be done using Data Actions? Or what advanced script should I use?
3. Is there an approach using scripting? But unbooked data can not use setUserinput(), when l show unbooked data, then there is performance problem because of too much unbooked date.

Any help or example code would be greatly appreciated!

l saw this article (https://community.sap.com/t5/technology-q-a/sap-sac-data-action-copy-measure-from-one-row-to-another..., but it did not add new member and copy measures on this newly inserted row.

@N1kh1l 

Thank you,

Iker

# SAP Analytics Cloud

#SAP Analytics Cloud for planning

 

Accepted Solutions (1)

Accepted Solutions (1)

N1kh1l
Active Contributor

@iksuuu 

This requirement has multiple layers to it and its very difficult to provide an exact working code. I am providing some snippets from some similar requirements which you can adjust as per your requirement. Try to break this into parts.

  • Reading the selected contract number from table
  • Creating the planning number master data in the dimension
  • Assigning this member to a Data Action parameter
  • Execute the Data Action

 

Also I am assuming the Data Action would be already ready as its simply copying from planning number # to newly created one.

I do not have a logic of incrementing the counter every time but you could try reading all members of the dimensions planning number and see what is the last member sequence. Or you could have an attribute called sequence in the dimension and assign sequence number to it while creating the member.

Below is some form of rough scripting. I have not validated it for syntax as I took it from my old work and stitch it together so some syntax might be off.

//Reading the current  contract number members from  Table row selection
var sel =Table_1.getSelections();

	if (sel.length > 0) {
		var ContractmemberId = ArrayUtils.create(Type.string);
		
	for(var i=0;i<=sel.length;i++)
		{
	for (var dimensionId in sel[i]) {
 		
			
 		if (dimensionId === 'CONTRACT_NUMBER') {
			
 			var currentcontract = sel[i][dimensionId];

			if(ContractmemberId.indexOf(currentproduct) === -1 && currentcontract)
			{
			   ContractmemberId.push(currentcontract);
			
			}}
				
	

	}}}

//Create a script variable  MemberId of type planning member before the below

//Creating Planning number member

var planningnumberid=ContractmemberId+'_001' // think about how to increment the counter here


MemberId = ({id: "planningnumberid", description: "planningnumberid"); // you can change description

var result = PlanningModel_1.createMembers('PLANNING_NUMBER',MemberId);
if(result)
{
Application.showMessage(ApplicationMessageType.Success,"Member Successfully Created");

// Assigning the parameter to Data Action
DataAction_1.setParameterValue("P_Planningnumber",planningnumberid); // You need to have a parameter in your Data Action for planning number



Application.showBusyIndicator("Preparing for execution..."); 
DataAction_1.execute();
Application.refreshData();
Application.hideBusyIndicator();
Application.showMessage(ApplicationMessageType.Success,"Executed Successfully");


}
else
{
Application.showMessage(ApplicationMessageType.Error,'Failed to create Member');
						
}

 

Hope this will help !!

Nikhil

iksuuu
Explorer
0 Likes
Hi Nikhil, thank you very much for your reply! It helps me to have clear steps and hints to finish the task. Thanks again!

Answers (0)