cancel
Showing results for 
Search instead for 
Did you mean: 

SAC app: updateMembers and checkbox widgets

igladyshev
Explorer
0 Kudos

I'm trying to use updateMembers() in my app to manage property values of a dimension Dim1 in my planning model.

For this I use a checkboxgroup widget where Selected Items should pass 'X' value to the property Flag of a corresponding Member, and NotSelected Items correspond to the empty '' values.

There is a tab, a checkboxgroup and a button in my app.

I use following code in canvas onInit script to fill checkboxgroup with initial items from Dim1

MemberArray = MyModel.getMembers("Dim1");
for(var k = 0; k < MemberArray.length; k++) 
	{
	//transfer all CP to ChBox	
	CheckboxGroup_1.addItem(MemberArray[k].id, MemberArray[k].description);
	if (MemberArray[k].properties["Flag"] === "X") 
		{	
		SelStrArray.push(MemberArray[k].id);	
		}
	CheckboxGroup_1.setSelectedKeys(SelStrArray);		
	};

I use following code in Button onClick script to synchronize tab and checkboxgroup:

Application.showBusyIndicator();
//clean up all property values
MemberArray = MyModel.getMembers("Dim1");
for(var k = 0; k < MemberArray.length; k++) 
	{
		Member = ({ id: MemberArray[k].id,
					 properties: { Flag: "" 							 
								 }});
		AllMemberArray.push(Member);		
	};
if ( AllMemberArray.length > 0 ) 
	{
		MyModel.updateMembers( "Dim1", AllMemberArray );
	};
//fill selected property values
SelStrArray = CheckboxGroup_1.getSelectedKeys();
for(var i = 0; i < SelStrArray.length; i++) 
	{
		Member = ({ id: SelStrArray[i],
					 properties: { Flag: "X" 							 
								 }});
		SelMemberArray.push(Member);
	};
if ( SelMemberArray.length > 0 ) 
	{
		MyModel.updateMembers( "Dim1", SelMemberArray );	
	};
Table_1.getDataSource().refreshData();
Application.hideBusyIndicator();

Unfortunately, the app works as expected only after the first click on the Button. All subsequent clicks don't remove 'X' from property values, but are only able to add them.

I'm not experienced in JavaScript, so I could misinterpret some syntax, or some used APIs are generally not working in SAC...

Please help to understand. I would appreciate to know other possible scenarios allowing to manage Member Properties from EndUser perspective in the App.

View Entire Topic
igladyshev
Explorer
0 Kudos

Thank you, Nikhil, for your fast response and such a detailed analysis. Yes, not cleaning up an array was a reason of this behaviour. And thanks for your script, will know now these tricks with consol.log and .showmessage allowing to "debug" the scripts. We all transform form ABAP'ers to JavaScript'ers this way soon 🙂

I'll allow myself one small question more.

I tried to show ID and Description of Dim1 in the CheckBoxGroup using this script below, but only description is shown for some reason - any thoughts why is it so?

CheckboxGroup_1.addItem(InitMemberArray[k].id, InitMemberArray[k].description);
N1kh1l
Active Contributor

igladyshev

Widgets like Dropdowns, Checkbox group show description if they are available. If you want to show id and description, you can set description to id+"-"+description.

CheckboxGroup_1.addItem(MemberArray[k].id, MemberArray[k].id+"-"+MemberArray[k].description);

Nikhil