on ‎2018 May 18 5:31 PM
Hi
I am trying to create a smartform attached to a odata service with cds view. I am able to create smartfilter and table successfully using annotations and metadata.xml but am stuck up in smartform. The view renders fine with smartfields but the catch is that I have to define entitySet for each of the smartfield whereas in sample applications I checked this was not required.If I remove the entity set from smartfield the smartfield is not rendered. Here is the sequence of steps I followed
Step1: I imported odata service and created a default model.
Step2: Created local annotations file based on data service and it looks as below:
<Annotations Target="ZCustomService.ZCustomServiceType"> <Annotation Term="Common.SemanticKey"> <Collection> <PropertyPath>abc</PropertyPath> </Collection> </Annotation> </Annotations>
In metadata same property exists as below:
<Property Name="abc" Type="Edm.String" MaxLength="4" sap:display-format="UpperCase" sap:creatable="true" sap:updatable="true" sap:label="Purchase Order"/>
In my view, I am using smartform as below:
<sap.ui.comp.smartform:SmartForm xmlns:sap.ui.comp.smartform="sap.ui.comp.smartform" xmlns:sap.ui.comp.smartfield="sap.ui.comp.smartfield" id="__form1"> <sap.ui.comp.smartform:groups> <sap.ui.comp.smartform:Group label="Group title" title="Group title" id="__group0"> <sap.ui.comp.smartform:groupElements> <sap.ui.comp.smartform:GroupElement id="__element0"> <sap.ui.comp.smartform:elements> <sap.ui.comp.smartfield:SmartField id="__field0" value="{abc}" entitySet ="ZCustomService"/> </sap.ui.comp.smartform:elements> </sap.ui.comp.smartform:GroupElement> </sap.ui.comp.smartform:groupElements> </sap.ui.comp.smartform:Group> </sap.ui.comp.smartform:groups> </sap.ui.comp.smartform:SmartForm>
Request your expert advice here..
I have also gone through blogs published on SCN but I dont see these options
https://blogs.sap.com/2016/04/22/how-to-use-smart-templates-with-sap-web-ide-extensibility/
https://blogs.sap.com/2017/06/06/dynamic-field-control-using-annotations-in-sapui5/
Request clarification before answering.
Hi Justin,
Please check how I use the Smart Form component on this simple Smart Form SAPUI5 application. I believe your issue has something to do with the xml view. Apparently, you are using some invalid tags and this may have a bad impact on the smart field controls. Please check the documentation here.
Therefore I have a couple of recommendations to you:
1) Don't use a namespace that is the same as the component namespace. Declare the namespace directly on the View to make your UI components more readable.
2) I couldn't find any documentation for the smart form api related to tags "groups" and "elements". So, I believe it’s safe to get rid of them. It also makes your code more human readable: </sap.ui.comp.smartform:elements> <<-- elements and groups are not part of the smartform api.
3) Check how to declare the namespace and latter how to use it on your xml view:
<mvc:View controllerName="SimpleSmartForm.controller.SmartForm"
xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc"
xmlns:smartForm="sap.ui.comp.smartform" xmlns:smartField="sap.ui.comp.smartfield"
displayBlock="true" xmlns="sap.m">
4) Check how simpler it is to read the following xml:
<smartForm:SmartForm id="simpleSmartFormId" editable="true">
<smartForm:Group label="Smart Form Group">
<smartForm:GroupElement label="Title">
<smartField:SmartField value="{/resultData/0/title'}" />
</smartForm:GroupElement>
<smartForm:GroupElement label="Description">
<smartField:SmartField value="{/resultData/0/text}" />
</smartForm:GroupElement>
</smartForm:Group>
</smartForm:SmartForm>
5) Smart Forms are made to be used in conjunction with a list selector. So, you need to embed the Smart Form on a page for which the binding gets propagated from the item that is selected (example: Master View Detail sample app). On my sample app, I manually created a JSON model and bound one element at a time to the page's smart form. Please notice that this way isn't the only way of displaying data on a Smart Form. You should bind a navigation property from the main collection (list selector) that points to the data the form is supposed to display. On the above code I have entered the binding and specified I want to display the 1st record it finds on resultData collection.
6) AFAIK: The usage of OData V2 annotations for Smart Forms UI components are limited and the service should deal with them directly. I see you already have a few of them. So, for instance, the annotation "sap:label" will place a label automatically on the smart field when it gets mapped to ktext attribute of the Odata. <Property Name="ktext" Type="Edm.String" MaxLength="40" sap:label="Work Center"/> More options are available to OData V4. To check how each annotation affects each Smart Field control, please check the documentation here. This documentation has both variants for V2 and V4.
7) I don't think you need a local annotation file for what you are trying to achieve. AFAIK: The Smart Form control doesn't work like the Smart Table control in the sense of allowing you to select fields to be displayed from the service's metadata without having to enter them manually on the xml view - like you are doing currently.
In that sense, if this becomes an issue to your design, then you might want to look at the Object Pages. Internally an OP will make usage of a Smart Form to allow used to edit data. But you don't build manually the Smart Form tags. That's taken care by the OP and the local annotations. Hope this helps.
Regards, Ivan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Justin,
I believe your annotation file is missing some UI.DataField elements or UI.DataPoints. Smart Components required this annotations in order to display elements on the screen - No element is displayed by default on any smart control. This is well explained on this blog.
Regards,
Ivan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
<edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" xmlns:sap="http://www.sap.com/Protocols/SAPData" xmlns:ux="http://www.sap.com/Protocols/OData4SAP/UX" xmlns:gp="http://www.sap.com/Protocols/SAPData/GenericPlayer" Version="1.0"> <edmx:DataServices xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:DataServiceVersion="2.0"> <Schema xmlns="http://schemas.microsoft.com/ado/2008/09/edm" Namespace="ZCustom" sap:schema-version="1" xml:lang="en"> <EntityType Name="ZCustomType" sap:content-version="1" sap:label="Purchase Order Request"> <Key> <PropertyRef Name="Id"/> <PropertyRef Name="s_num"/> </Key> <Property Name="auart" Type="Edm.String" MaxLength="4" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false" sap:display-format="UpperCase" sap:label="Service Request"/> <Property Name="ilart" Type="Edm.String" MaxLength="3" sap:display-format="UpperCase" sap:label="Function Location"/> <Property Name="tplnr" Type="Edm.String" MaxLength="40" sap:display-format="UpperCase" sap:label="Asset"/> <Property Name="ktext" Type="Edm.String" MaxLength="40" sap:label="Work Center"/> <Property Name="job_title" Type="Edm.String" sap:label="Job Title"/> <Property Name="scope" Type="Edm.String" sap:label="Scope of Work"/> </EntityType> <ComplexType Name="ZCustomValidationFunction"> <Property Name="IsValid" Type="Edm.Boolean" Nullable="false" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/> </ComplexType> <EntityContainer Name="ZCustom_Entities" m:IsDefaultEntityContainer="true" sap:supported-formats="atom json xlsx"> <EntitySet Name="ZCustom" EntityType="ZCustom.ZCustomType" sap:content-version="1"/> <FunctionImport Name="ZCustomAct" ReturnType="ZCustom.ZCustomType" EntitySet="ZCustom" m:HttpMethod="POST" sap:applicable-path="PCA5CD0EEC74BDB164FD51537863EBBD3" sap:action-for="ZCustom.ZCustomType"> <Parameter Name="Id" Type="Edm.Int32" Mode="In"/> <Parameter Name="s_num" Type="Edm.String" Mode="In"/> </FunctionImport> <FunctionImport Name="ZCustomEdit" ReturnType="ZCustom.ZCustomType" EntitySet="ZCustom" m:HttpMethod="POST" sap:applicable-path="P05D289BF56910A8AAAFA1C7749BD8E1B" sap:action-for="ZCustom.ZCustomType"> <Parameter Name="PreserveChanges" Type="Edm.Boolean" Mode="In" Nullable="true"/> <Parameter Name="Id" Type="Edm.Int32" Mode="In"/> <Parameter Name="s_num" Type="Edm.String" Mode="In"/> </FunctionImport> </EntityContainer> <Annotations xmlns="http://docs.oasis-open.org/odata/ns/edm" Target="https://abc.hana.ondemand.com:443/odata/SAP/ZCustom/$metadata"> <Annotation Term="Common.DraftRoot"> <Record> <PropertyValue Property="ActivationAction" String="ZCustom.ZCustom_Entities/ZCustomAct"/> <PropertyValue Property="EditAction" String="ZCustom.ZCustom_Entities/ZCustomEdit"/> </Record> </Annotation> </Annotations> <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="self" href="https://abc.hana.ondemand.com:443/odata/SAP/ZCustom/$metadata"/> <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="latest-version" href="https://abc.hana.ondemand.com:443/odata/SAP/ZCustom/$metadata"/> </Schema> </edmx:DataServices> </edmx:Edmx>
| User | Count |
|---|---|
| 5 | |
| 5 | |
| 4 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.