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

Adding association as input parameter for custom action in CAP

David21
Explorer
0 Kudos
1,782

Hello everyone,

I'm using CAP(Node.js) with odata(v4) & fiori elements. I am creating a custom add button so that user can add multiple values from valuehelp to draft rather than using the create button which allows you to create only one entry at a time.  As we know that you can't use associations as an input parameter of custom actions, So I have been using a workaround for it. Create a type in cds service file with a field that has type array of string i.e type customType{someField : array of String}, Use this field as an input parameter i.e. action someAction( someField: customType : someField), And then assigning a valueHelp to this field through annotations. 

This works fine if the associated entity has only one key. But if the associated entity has two key fields  i.e. composite key, there doesn't seem to be a way to store both the keys from the valueHelp. Any ideas on how to achive this ?

I used the following blog to implement this work around (6. Action with Value Help Input) : 

https://community.sap.com/t5/technology-blogs-by-sap/cap-with-fiori-elements-actions-on-list-report-...

View Entire Topic
David21
Explorer
0 Kudos

I think essentially it's doing the same thing that my approach does. You have assigned the action a valuehelp and storing the data in a string field

AuthorisationType : String(30)

 And then in the JS file you are creating a draft for that entity with the inputed data. But if you assign the action's input type a field that is an association field i.e.

someAction(inp : someEntity : associationFeildOfThatEntity)

Or any variation of this it will give you an error. The issue is that if the associated entity i.e. the entity in the Collection path of the value help has a composite key then that means that every single column has values that are repeating, And if the user tries to select multiple values , it will only let you select those that have different values in the field 

ValueListProperty

Thus ignoring some of the values .