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

How to set default value for parameter of action bound to multiple instances(Collection) in CAP

David21
Explorer
0 Kudos
1,042

Hello everyone,

I'm using CAP(Node.js) with odata(v4) & fiori elements. I've a composition between two entities, lets call them parent and child. They are displayed on the UI such that on the object page of parent entity i have displayed the child entity in the form of Line Items .I have created an action bound with the child entity and it takes an input parameter with a default value, the default value is a field from the parent Entity using the annotation 

@UI.ParameterDefaultValue: in.parentEntity.field. But my requirement is that this action button has to be available/clickable even without selecting a record from the child entity so i had to make it a static action using the 'many' keyword i.e. An action bound to multiple instances of the entity rather that a single instance that has been selected, the old way of doing this was using the annotaion @CDS.odata.bindingparameter.collection.
 
Now the problem with binding it with multiple instances of the entity is that it doesn't let you give the default value for it's parameter using @ui.ParameterDefaultValue: in.parentEntity.field  because now it doesn't know which instance to take the value from.
 
One workaround i found for this problem was that i binded the action to the parent entity & placed the button at top the object page of parent entity. Now it can easily get the default value i.e.  @ui.ParameterDefaultValue: in.field & be available at all times. But the requirement is to show the button on the toolbar of child entity's table(where the create & delete buttons are) & it seems that using fiori elements you can only put the action button there if its bounded to the same entity.
 
So is there a way to: (a)Give default value as a parameter for action bound to multiple instances of an entity ? OR (b)Somehow move the action button from top of parent's object page down to the toolbar of its child table while still being bound to the parent entity ?

Accepted Solutions (0)

Answers (1)

Answers (1)

sandeep_rs
Product and Topic Expert
Product and Topic Expert

Hi,

I guess you are already familiar with the V4 specific section "Default Values for Action Parameters" in page that details the many possible ways in which an action parameter dialog can be supplied with default values - did you try that out? I see it makes no distinction between bound or static (bound to entity) - so it should have worked!

There is also the line: "In multiselection scenarios (when the user has selected multiple table lines to execute a bound action), the parameter value is only prefilled if all source values are the same." which clarifies the behavior in case you are trying to assign a default value using one of the table fields!

Best Regards,

   Sandeep

David21
Explorer
0 Kudos

Hi sandeep, Yes i am familiar with this documentation. When i try to use the same method to provide default value in static action it i.e. in.parentEntity.field, it highlights this part and shows the error : "Path in.parentEntity.field leads to Collection(Edm.String). The path should lead to type Edm.String".

It seems that because it's bound to all instances of the entity it can't figure out which particular instance to use to get the data. And the source value in this case will be the same as all instances of the child entity are linked to the same instance of the parent.