Reputation: 1
I'm currently working on a SAP CAP (Cloud Application Programming) project where I've implemented a service (FarmboService) with entities such as Plants, Garden, WateringEvent, and associations between them. In my UI application, specifically in the Plant creation/modification screen, I'm trying to add a field that allows users to choose from a list of Watering Events as occurrences for a plant. The challenge is that each plant can have multiple watering event occurrences.
I've provided relevant portions of my CDS annotations and UI application code in the question details. I need guidance on how to implement a Value Help for the Watering Events in this context and allow multiple selections for a single plant.
Any assistance or insights into achieving this functionality would be greatly appreciated. Thank you.
This introduction provides a brief overview of the problem, mentions the technologies involved, and highlights the specific challenge you're seeking help with.
here's my schema.cds
namespace my.farmbot;
using { cuid } from '@sap/cds/common';
entity Plants : cuid {
key ID : Integer;
garden : Association to Garden;
radius : Double;
x : Double;
y : Double;
name : String;
wateringEvents : Association to many PlantWateringAssociation on wateringEvents.plant = $self;
}
entity Garden {
key ID : Integer;
name : String;
plants : Association to many Plants on plants.garden = $self;
}
entity PlantWateringAssociation : cuid {
key ID : Integer;
plant : Association to Plants;
wateringEvent : Association to WateringEvent;
}
entity WateringEvent: cuid {
key ID: Integer;
WateringType: String;
Occurrence: Integer;
createdAt: DateTime;
createdBy: String;
modifiedAt: DateTime;
modifiedBy: String;
plants : Association to many PlantWateringAssociation on plants.wateringEvent = $self;
}
farmbot-service.cds
using my.farmbot as my from '../db/level';
service FarmboService {
entity Plants @(
Capabilities : {
InsertRestrictions : {
$Type : 'Capabilities.InsertRestrictionsType',
Insertable : true
},
UpdateRestrictions : {
$Type : 'Capabilities.UpdateRestrictionsType',
Updatable : true
},
DeleteRestrictions : {
$Type : 'Capabilities.DeleteRestrictionsType',
Deletable : true
}
}
) as SELECT from my.Plants ;
annotate Plants with @odata.draft.enabled;
entity Garden @(
Capabilities : {
InsertRestrictions : {
$Type : 'Capabilities.InsertRestrictionsType',
Insertable : true
},
UpdateRestrictions : {
$Type : 'Capabilities.UpdateRestrictionsType',
Updatable : true
},
DeleteRestrictions : {
$Type : 'Capabilities.DeleteRestrictionsType',
Deletable : false
}
}
) as SELECT from my.Garden;
annotate Garden with @odata.draft.enabled;
entity WateringEvent @(
Capabilities : {
InsertRestrictions : {
$Type : 'Capabilities.InsertRestrictionsType',
Insertable : true
},
UpdateRestrictions : {
$Type : 'Capabilities.UpdateRestrictionsType',
Updatable : true
},
DeleteRestrictions : {
$Type : 'Capabilities.DeleteRestrictionsType',
Deletable : false
}
}
) as SELECT from my.WateringEvent;
entity PlantWateringAssociation as SELECT from my.PlantWateringAssociation;
}
app/plants/annotations.cds
using FarmboService as service from '../../srv/farmbot-service';
annotate service.Plants with @(
UI : {
Identification : [{Value: name}],
SelectionFields: [
name,
],
LineItem : [
{Value: ID,
Label : '{i18n>PlantID}'},
{Value: name,
Label : '{i18n>name}'},
{Value: radius, Criticality: level,
Label : '{i18n>radius}' },
{Value: garden.name,
Label : '{i18n>GardenName}'},
{Value : wateringEvents.wateringEvent.WateringType,
Label : '{i18n>Type}'},
{Value : wateringEvents.wateringEvent.Occurrence,
Label : '{i18n>Occurence}'},
],
HeaderInfo : {
TypeName : '{i18n>Plant}',
TypeNamePlural: '{i18n>Plants}',
Title : {Value: name},
Description : {Value: garden.name}
},
}
);
annotate service.Plants with {
ID @title: '{i18n>PlantID}';
name @title: '{i18n>name}';
radius @title: '{i18n>radius}';
garden @title: '{i18n>garden}';
};
annotate service.Plants with @(
UI.FieldGroup #GeneratedGroup1: {
$Type: 'UI.FieldGroupType',
Data : [
{
$Type: 'UI.DataField',
Value: ID,
Label : '{i18n>PlantID}',
},
{
$Type: 'UI.DataField',
Value: name,
Label : '{i18n>name}',
},
{
$Type: 'UI.DataField',
Value: radius,
Label : '{i18n>radius}',
},
{
$Type: 'UI.DataField',
Label: '{i18n>X}',
Value: x,
},
{
$Type: 'UI.DataField',
Label: '{i18n>Y}',
Value: y,
},
{
$Type: 'UI.DataField',
Label: '{i18n>garden}',
Value: garden_ID,
},
{
$Type: 'UI.DataField',
Label: '{i18n>Occurrence}',
Value: wateringEvents.wateringEvent.Occurrence,
},
{
$Type: 'UI.DataField',
Label: '{i18n>Type}',
Value: wateringEvents.wateringEvent.WateringType,
},
],
},
UI.Facets : [{
$Type : 'UI.ReferenceFacet',
ID : 'GeneratedFacet1',
Label : '{i18n>GeneralInformation}',
Target: '@UI.FieldGroup#GeneratedGroup1',
}, ],
);
annotate service.Plants with {
garden @(Common.ValueList : {
$Type : 'Common.ValueListType',
CollectionPath : 'Garden',
Parameters : [
{
$Type : 'Common.ValueListParameterInOut',
LocalDataProperty : garden_ID,
ValueListProperty : 'ID',
},
],
},
Common.ValueListWithFixedValues : true
)};
annotate service.Garden with {
ID @Common.Text : {
$value : name,
![@UI.TextArrangement] : #TextOnly,
}
};
annotate service.Plants with {
garden @Common.Text : {
$value : garden.name,
![@UI.TextArrangement] : #TextOnly,
}
};
I expect to have a Fiori annotation solution that allows me to include a Value Help field during the creation/modification of a Plant. This field should enable the selection of one or multiple Watering Events for the newly created Plant.
Upvotes: 0
Views: 301
Reputation: 13
By using composition instead of association you should be able to get a multi-select dropdown for wateringEvents.
wateringEvents is a one-to-many navigationProperty pointing to the "PlantWateringComposition" entity.
entity Plants : cuid {
...
@cascade: {delete}
wateringEvents : Composition of many PlantWateringComposition on wateringEvents.plant = $self;
}
entity PlantWateringComposition : cuid {
plant : Association to one Plants @mandatory;
WateringType: String
}
For the Value help
//value help for Plants
annotate service.Plants with {
WateringType @(Common: {
ValueListWithFixedValues: true,
ValueList : {
CollectionPath: 'WateringEvent',
Parameters : [
{
$Type : 'Common.ValueListParameterInOut',
ValueListProperty: 'WateringType',
LocalDataProperty: WateringType
}
]
}
});
}
Accordingly, you'll need to update LineItem & FieldGroup
Value : wateringEvents.WateringType
Refer: https://sapui5.hana.ondemand.com/sdk/#/topic/04ff5b1a81344a8e8169ea99630ff4e5
Upvotes: 0