on 2021 Feb 18 11:39 AM
Hi Experts,
I have a RAP based oData service, which is composed on a parent and its child entities. Now, we have a requirement to add a Value Help for one of the child entity field. I have 2 issues here:
1. The source CDS of this Value help is a parametrized CDS. How can I pass parameters along with entity name in @consumption.valuehelpDefinition annotation?
2. I want to filter records in this Value help on the basis of a field value from its parent entity.
Could you please help?
Thanks,
Aman Garg
Request clarification before answering.
Hello,
I found solution based on Prefilling Fields Using the DefaultValuesFunction - Documentation - Demo Kit - SAPUI5 SDK
I created in backend function with parameters which contains keys of parent entity. That function is called before create new instance of entity and fields which are used for field for value help were prefilled. You even shouldn't show these fields on the screen. I don't know how to was implemented frontend part because unfortunately I'm not full stack developer. But I think experienced fullstack or frontend developer can understand what he/she should do based on help which I added above.
In behavior of entity which is going to use predefined fields add row
static function SetDefaultFieldsForFilter parameter zi_abstract_entity_with_parent_keys result [1] $self;
Then in behavior pool class implement corresponding method as such
LOOP AT keys ASSIGNING FIELD-SYMBOL(<key>).
READ ENTITIES OF zi_root_entity IN LOCAL MODE
ENTITY root_entity
ALL FIELDS WITH VALUE #( ( rootentitykey= <key>-%param-rootentitykey) )
RESULT DATA(lt_root_instances).
ASSIGN lt_root_instances[ 1 ] TO FIELD-SYMBOL(<ri>).
IF sy-subrc <> 0.
CONTINUE.
ENDIF.
APPEND VALUE #( %cid = <key>-%cid
%param-keyofchildentity = <key>-%param-keyofchildentity
%param-fieldfromroot1forfilter1= <ri>-fieldfromroot1
%param-fieldfromroot2forfilter2= <ri>-fieldfromroot2
%param-currencycode = c_currency_eur "if you want to add definite value for field) TO result.
ENDLOOP.
It is look more like workaround, but I didn't find other way how to use fields from parent entity for value help in child entity as filter during creation of new instance of child entity in managed without draft application.
P.S. Sorry that I didn't wrap code into code tag but I didn't find how to do that. Maybe somebody hint me ho to do that 🙂
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If your requirement is to purely pass the parent entity's value's to a child entity's value help I'd do what I have done below. This is in the metadata extension of the item entity's field for which the value help is bound. In my case I had a material look up for which I had to send the plant, storage location and an external product group from the header. the material itself is picked up for the line item.
The one thing I am struggling with this approach is when the look up entity has a parameter. Even though the additional binding field has a parameter field, it doesn't bind and doesn't pick up values.
Perhaps @CarineTchoutouo would know a way around it 🙂
@Consumption.valueHelpDefinition: [{
entity : { name : 'ZZC_MaterialLookUp' , element : 'Material' },
additionalBinding: [
{ element : 'Plant' , localElement: '_Header.Plant' , usage : #FILTER } ,
{ element: 'StorageLocation', localElement: '_Header.Outlet', usage :#FILTER },
{ element: 'ExternalProductGroup', localElement: '_Header.Commodity', usage : #FILTER },
{ element: 'Supplier', localElement: 'Supplier', usage :#RESULT },
{ element: 'OrderUnit', localElement: 'OrderUnit', usage :#RESULT },
{ element: 'NetPrice', localElement: 'NetPrice', usage :#RESULT },
{ element: 'Currency', localElement: 'Currency', usage : #RESULT }
]
}]
@TharinduWdid you seriously think that I haven't try that code? That didn't work for me. There is only difference I wrote these annotations in projection view not in metadata extension maybe that is cause that it didn't work. And again I want to emphasize that value help didn't work for new record on the screen where record is created. I'll check your solution, but I don't believe that it works.
Well I don't know you so don't really what you've tried either 😄 I've deployed this on production so works great for me. Like I said the one thing I can't do is have the value help accept parameters. As soon as that's done, my odata v4 RAP service is generatee for odata v4.01 which isn't supported by Fiori Elements. But as far as passing parent entity's fields into the value help of a child entity it works. Note that in my additional binding, the local element accesses the parent element through the association-to-parent. It works in both create, update and draft modes for me. I am on S/4HANA 2023 FPS02 On Premise.
@TharinduW, ok there is one more difference - oData V4. I tried for oData v2, sometimes it works in different way. But anyway if your solution works I'll be happy and thankful 😄
About parameters for value help check annotation @Consumption.derivation there is a help https://help.sap.com/doc/saphelp_nw75/7.5.5/en-US/d6/0c0bf6798a481fb7412bc89934cb8a/frameset.htm
User | Count |
---|---|
62 | |
8 | |
7 | |
7 | |
5 | |
5 | |
5 | |
4 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.