cancel
Showing results for 
Search instead for 
Did you mean: 

Error when creating the view in Fiori Cannot read property of undefined

ngoxuanhieu
Explorer
0 Kudos

Hi Experts!

I am developing Java CAP application on SBAS. I implemented the UI using annotation from the CDS model. I have a list of reports and have navigation to the Object Pages of each row of data.

Here is the structure of the project

admin-service.cds

using cnma.businesspartner as cnma from '../db/schema';

@path:'admin'
service AdminService {

    entity BusinessPartners as select from cnma.BusinessPartners;
    entity Addresses as projection on cnma.Addresses;
    entity Communications as projection on cnma.Communications;
    entity CloudPersons as projection on cnma.CloudPersons;
    entity PersonBusinessPartnerAssignments as projection on cnma.PersonBusinessPartnerAssignments;
    entity Documents as projection on cnma.Documents;
}

// Enable Fiori Draft
annotate AdminService.BusinessPartners with @odata.draft.enabled : true; // open button create and edit with this annotation
annotate AdminService.BusinessPartners with @fiori.draft.enabled : true;

annotate AdminService.Addresses with @fiori.draft.enabled : true;

common.cds

/*
  Common Annotations shared by all apps
*/
using { cuid } from '@sap/cds/common';
using {cnma.businesspartner as cnma} from '../db/schema';

//  Fiori requires generated IDs to be annotated with @Core.Computed
annotate cuid with {
    ID @Core.Computed
}

// Business Partner Object Common
annotate cnma.BusinessPartners with {
    description @UI.MultiLineText;
}
annotate cnma.BusinessPartners with @(
    UI: {
        Identification: [{Value:name}],
        SelectionFields: [ ID, sort ],
        HeaderInfo: {
            TypeName: 'BusinessPartner',
            TypeNamePlural: 'BusinessPartners'
        },
        LineItem: [
            {Value: ID},
            {Value: name},
            {Value: sort},
            {Value: homePage},
            {Value: duns}
        ]
    }
);

fiori-service.cds (in webapp directory)

using AdminService from '../../srv/admin-service';
using cnma from '../common';
/* Addresses - Communication - Document annotation has remove from here by limit character */

/* Business Partner Object Page */
annotate AdminService.BusinessPartners with @(
    UI: {

        // List of BusinessPartner
        SelectionFields: [ ID, businessPartnerNo, sort ],
        LineItem:[
            {Value: name , Label:'{i18n>bp.name}'},
            {Value: sort, Label:'{i18n>bp.sort}'},
            {Value: homePage, Label:'{i18n>bp.homePage}'},
            {Value: duns, Label:'{i18n>bp.duns}'},
            {Value: bpStatus.name, Label:'{i18n>bpStatus.main}'},
        ],

        // Detail of BusinessPartner
        HeaderInfo: {
            TypeName: 'BusinessPartner',
            TypeNamePlural: 'BusinessPartners',
            // Title: {Value: name, Label:'{i18n>bp.name}'},
            // Description: {Value: description, Label:'{i18n>bp.description}'},
            ImageUrl: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQMdby2azEu5hqNg-AfCniKM3XrYi_UmHCcIQ&usqp=CAU'
        },

        Facets: [
            {$Type: 'UI.ReferenceFacet', Label: '{i18n>GeneralInfo}', Target: '@UI.FieldGroup#GeneralInfo'},
            {$Type: 'UI.ReferenceFacet', Label: '{i18n>AdditionalInfo}', Target: '@UI.FieldGroup#AdditionalInfo'},
            {$Type: 'UI.ReferenceFacet', Label: '{i18n>Communications}', Target: 'communications/@UI.LineItem'},
            {$Type: 'UI.ReferenceFacet', Label: '{i18n>Addresses}', Target: 'addresses/@UI.LineItem'},
            {$Type: 'UI.ReferenceFacet', Label: '{i18n>Documents}', Target: 'bpDocuments/@UI.LineItem'},
            {$Type: 'UI.ReferenceFacet', Label: '{i18n>ContactPersons}', Target: 'personAssignments/@UI.LineItem'},
            {$Type: 'UI.ReferenceFacet', Label: '{i18n>Administrative}', Target: '@UI.FieldGroup#Administrative'},
        ],
        
        FieldGroup#GeneralInfo: {
            Data: [
                {Value: name, Label: '{i18n>bp.name}'},
                {Value: sort, Label: '{i18n>bp.sort}'},
                {Value: businessPartnerNo, Label: '{i18n>bp.businessPartnerNo}'},
                {Value: description, Label: '{i18n>bp.description}'},
                {Value: homePage, Label: '{i18n>bp.homePage}'},
                {Value: duns, Label: '{i18n>bp.duns}'},
                {Value: bpStatus_code, Label: '{i18n>bpStatus.code}'},
            ]
        },

        FieldGroup#AdditionalInfo: {
            Data: [
                {Value: founded, Label: '{i18n>founded}'},
                {Value: amtEmloyees, Label: '{i18n>amtEmloyees}'},
                {Value: turnOver, Label: '{i18n>turnOver}'},
                {Value: taxNumber, Label: '{i18n>taxNumber}'},
                {Value: vatTaxNumber, Label: '{i18n>vatTaxNumber}'}
            ]
        },

        FieldGroup#Administrative: {
            Data: [
                {Value: createdAt},
                {Value: createdBy},
                {Value: modifiedAt},
                {Value: modifiedBy},
            ]
        }
    },

    Common: {
        SideEffects#Addresses: {
            SourceEntities: [
                addresses
            ]
        },
        SideEffects#Documents: {
            SourceEntities: [
                bpDocuments
            ]
        },
        SideEffects#ContactPersonsChanged: {
            SourceEntities: [
                personAssignments
            ]
        }
    }
);

Component.js

sap.ui.define(["sap/fe/core/AppComponent"],
    ac => ac.extend("admin.Component", {
    metadata:{ manifest:'json' }
}))

manifest.json

{
    "_version": "1.8.0",
    "sap.app": {
        "id": "admin",
        "type": "application",
        "title": "{{appTitle}}",
        "description": "{{appDescription}}",
        "dataSources": {
            "AdminService": {
                "uri": "/api/admin/",
                "type": "OData",
                "settings": {
                    "odataVersion": "4.0"
                }
            }
        },
        "-sourceTemplate": {
            "id": "ui5template.basicSAPUI5ApplicationProject",
            "-id": "ui5template.smartTemplate",
            "-version": "1.40.12"
        }
    },
    "sap.ui5": {
        "dependencies": {
            "libs": {
                "sap.fe.templates": {}
            }
        },
        "models": {
            "i18n": {
                "type": "sap.ui.model.resource.ResourceModel",
                "uri": "i18n/i18n.properties"
            },
            "": {
                "dataSource": "AdminService",
                "settings": {
                    "synchronizationMode": "None",
                    "operationMode": "Server",
                    "autoExpandSelect" : true,
                    "earlyRequests": true,
                    "groupProperties": {
                        "default": {
                            "submit": "Auto"
                        }
                    }
                }
            }
        },
        "routing": {
            "routes": [
                {
                    "pattern": ":?query:",
                    "name": "BusinessPartnerList",
                    "target": "BusinessPartnerList"
                },
                {
                    "pattern": "BusinessPartners({key}):?query:",
                    "name": "BusinessPartnerDetails",
                    "target": "BusinessPartnerDetails"
                },
                {
                    "pattern": "BusinessPartners({boo})/addresses({boo2}):?query:",
                    "name": "AddressDetails",
                    "target": "AddressDetails"
                },
                {
                    "pattern": "BusinessPartners({boo})/communications({boo2}):?query:",
                    "name": "CommunicationDetails",
                    "target": "CommunicationDetails"
                },
                {
                    "pattern": "BusinessPartners({boo})/bpDocuments({boo2}):?query:",
                    "name": "BpDocumentDetails",
                    "target": "BpDocumentDetails"
                },
                {
                    "pattern": "BusinessPartners({boo1})/personAssignments({boo2}):?query:",
                    "name": "PersonAssignmentDetails",
                    "target": "PersonAssignmentDetails"
                },
                {
                    "pattern": "CloudPersons({key}):?query:",
                    "name": "CloudPersonDetails",
                    "target": "CloudPersonDetails"
                }
            ],

            "targets": {
                "BusinessPartnerList": {
                    "type": "Component",
                    "id": "BusinessPartnerList",
                    "name": "sap.fe.templates.ListReport",
                    "options": {
                        "settings" : {
                            "entitySet" : "BusinessPartners",
                            "navigation" : {
                                "BusinessPartners" : {
                                    "detail" : {
                                        "route" : "BusinessPartnerDetails"
                                    }
                                }
                            }
                        }
                    }
                },
                "BusinessPartnerDetails": {
                    "type": "Component",
                    "id": "BusinessPartnerDetails",
                    "name": "sap.fe.templates.ObjectPage",
                    "options": {
                        "settings": {
                            "entitySet": "BusinessPartners",
                            "navigation": {
                                "addresses":{
                                    "detail": {
                                        "route": "AddressDetails"
                                    }
                                },
                                "communications":{
                                    "detail": {
                                        "route": "CommunicationDetails"
                                    }
                                },
                                "bpDocuments": {
                                    "detail": {
                                        "route": "BpDocumentDetails"
                                    }
                                },
                                "personAssignments":{
                                    "detail": {
                                        "route": "PersonAssignmentDetails"
                                    }
                                },
                                "cloudPerson": {
                                    "detail": {
                                        "route": "CloudPersonDetails"
                                    }
                                }
                            }
                        }
                    }
                },
                "AddressDetails": {
                    "type": "Component",
                    "id": "AddressDetails",
                    "name": "sap.fe.templates.ObjectPage",
                    "options": {
                        "settings": {
                            "entitySet": "Addresses"
                        }
                    }
                },
                "CommunicationDetails": {
                    "type": "Component",
                    "id": "CommunicationDetails",
                    "name": "sap.fe.templates.ObjectPage",
                    "options": {
                        "settings": {
                            "entitySet": "Communications"
                        }
                    }
                },
                "BpDocumentDetails": {
                    "type": "Component",
                    "id": "BpDocumentDetails",
                    "name": "sap.fe.templates.ObjectPage",
                    "options": {
                        "settings": {
                            "entitySet": "Documents"
                        }
                    }
                },

                "PersonAssignmentDetails": {
                    "type": "Component",
                    "id": "PersonAssignmentDetails",
                    "name": "sap.fe.templates.ObjectPage",
                    "options": {
                        "settings": {
                            "entitySet": "PersonBusinessPartnerAssignments"
                        }
                    }
                },
                "CloudPersonDetails": {
                    "type": "Component",
                    "id": "CloudPersonDetails",
                    "name": "sap.fe.templates.ObjectPage",
                    "options": {
                        "settings": {
                            "entitySet": "CloudPersons"
                        }
                    }
                }
            }
        },
        "contentDensities": {
            "compact": true,
            "cozy": true
        }
    },
    "sap.ui": {
        "technology": "UI5",
        "fullWidth": false
    },
    "sap.fiori": {
        "registrationIds": [],
        "archeType": "transactional"
    }
}


When running the app, the list report display below

When clicking into a row, I get an error

Here is the console log

It's worth mentioning here: Previously I ran the application completely fine and didn't have any changes in the code, but all of a sudden this error pops up, I'm not sure if this is a CDS or Fiori error, or yes may be due to version. Another strange thing is that when I access the application by phone it works normally!

Any idea, what is missing and how to fix it? Any help would be appreciated (maybe a new missing annotation?).

Best Regards
Hieu

gregorw
Active Contributor

Your issue would be a lot easier to replicate if you share your code on a public Git repository instead of posting all the code here.

maheshpalavalli
Active Contributor

click on f12 and share the console error log as well for a better solution

ngoxuanhieu
Explorer
0 Kudos

hi maheshkumar.palavalli, I have updated the question and include the console log, hope it's clear enough for you, any support I would appreciate!

krantikartan
Discoverer
0 Kudos

Hi All,

I am trying to build the ALP app using services of java CAPM odata, when inputed the local annotation for chart and trying to filter the data. Template is giving error.

template-issue.png

jerryjanda
Community Manager
Community Manager
0 Kudos

We're glad to have you in the community looking for answers to your questions, but you posted a question as an answer (which I converted to a comment) in a thread that doesn't seem related to your topic.

I want you to get the help you need, but you're unlikely to get any responses this way. Therefore, I'd like to offer some friendly advice:

* Try asking a new question instead at https://answers.sap.com/questions/ask.html.

* Familiarize yourself with https://community.sap.com/resources/questions-and-answers, as it provides tips for preparing questions that draw responses from our members.

* Take our Q&A tutorial at https://developers.sap.com/tutorials/community-qa.html, as that will also help you when preparing questions for the community.

* Complete your profile by following the steps at https://developers.sap.com/tutorials/community-profile.html, as a complete profile encourages readers to respond.

I hope you find this advice useful, and we're happy to have you as part of SAP Community!

Kind regards,

--Jerry

Moderation Lead

Accepted Solutions (0)

Answers (1)

Answers (1)

ngoxuanhieu
Explorer

The issue has solved, just add again two-sections for HeaderInfo of the entity

0 Kudos

had exactly the same issue, solved the same way. Thanks for sharing!