Skip to Content
Feb 05, 2022 at 06:46 AM

How to use the @Communication.IsPhoneNumber annotation in my SAP Fiori Elements apps?

665 Views Last edit Feb 05, 2022 at 06:52 AM 2 rev


The title of my post pretty much describes my problem.

I am developing some prototype applications based on SAP Fiori Element (along with SAP CAP and SAP HANA DB).

I'm testing (and learning how to use various annotations). At the moment, all the annotations that I am using are at the level of the definition of the domain model (database) and the definition of the service. That is, at the level of CDS files.

I want to know:

What is the @Communication.IsPhoneNumber (SAP Vocabulary) annotation for?

And mainly, how is that annotation used? (some examples would be useful)

I have already tried, understood, and seen the effects of other annotations like @Communication.IsEmailAddress. This allows me, for example, to validate that the user's input is an email address (as I show in the first screenshot attached).

However, unlike what I expected, the @Communication.IsPhoneNumber annotation doesn't work the same or doesn't seem to work (I don't know if I'm not using it correctly). For example, I can enter any text string into a field annotated with @Communication.IsPhoneNumber (as shown in the second screenshot attached).

To further clarify the way I'm using the annotation (because maybe the problem is that I'm not using it properly), I'm sharing two code snippets below that show it.

1. I have a file (sme_common.cds) with common definitions for the entire project. In a part of that file is the following fragment:

type LongName : localized String(111);
type ShortDescription : localized String(111)  @Core.Description;
type LongDescription  : localized String(1111) @Core.LongDescription;
type EmailAddress     : String(320) @Communication.IsEmailAddress;
type PhoneNumber      : String(15)  @Communication.IsPhoneNumber;   // <---------------
type ComputingPath    : String(4096);
type URL              : String(2048) @Core.IsURL;

//----- Common number types<
type Percentaje : Decimal(2,2) @assert.range:[0,100] @Measures.Unit : '%';

2. In the domain model definition (Data), I have the following:

using { Country as SAP_Country } from '@sap/cds/common';
using { sme.common as SME } from '../common/sme_common';

entity Companies: SME.BaseMaster {
    country : SAP_Country not null;

    shortDescr : SME.ShortDescription;
    longDescr  : SME.LongDescription;
    email : SME.EmailAddress @title: 'EMAIL';
    phone : SME.PhoneNumber  @title: 'PHONE';   // <---------------
    myUrl : SME.URL          @title: 'URL';

How can I validate that a data field accepts only strings that are valid phone numbers (such as +58 424-4164922 or 0412 422-8342) using SAP Fiori Elements annotations?

it's possible?

Thanks in advance for any help and/or suggestion.


scrcap-01.png (59.7 kB)
scrcap-03.png (63.2 kB)