如何給SAP Cloud for Customer UI上的欄位新增自定義校驗邏輯
There is a good blog SAP Cloud for Customer Phone Number Parsing and Formatting which gives a detail explanation about the parse logic of phone number parse logic in C4C. By default it allows the Alphanumeric Value to be entered, the reason of this behavior is explained in note 2525818 – In an Account and Contact, the Phone Number Allows Alphanumeric Value.
However, at least in China, a valid mobile phone number only consists of pure numeric values. The requirement of local customer is whenever the value other than pure number is maintained, the error message will be popped up and the save is terminated.
The fulfilled scenario is: for example if I input an “A” character in Mobile field and press save button, error message is raised:
And save is prevented.
Here below is how to achieve this custom validation logic in Cloud Application Studio. Create an extension field phoneInvalidRel in BO BusinessPartnerRelationship, and declare the error message to be raised when invalid digit is detected.
Implement BeforeSave event. This event is responsible to check whether the mobile phone number consists of pure numeric value and set the check result into extension field phoneInvalidRel, which will be used by onSave Validation later.
import ABSL;var phone;this.phoneInvalidRel = false;var BPRelationship = this;if ( !BPRelationship.ContactPerson.IsSet())
return;var contact = BPRelationship.ContactPerson;if( !contact.ContactPersonWorkplaceAddressInformation.IsSet())
return;var workplaceAddress = contact.ContactPersonWorkplaceAddressInformation;if( !workplaceAddress.ContactPersonWorkplaceAddress.DefaultMobilePhone.IsSet())
return;phone = workplaceAddress.ContactPersonWorkplaceAddress.DefaultMobilePhone;if( phone.FormattedNumberDescription.IsInitial())
return;if( phone.FormattedNumberDescription.FindRegex("1\\d{10}") < 0){
// raise "Invalid mobile phone number!"; this.phoneInvalidRel = true;
raise Error_phone_msg_rel.Create("E", phone.FormattedNumberDescription );}
Implement OnSave validation, and simply use the check result stored in extension field phoneInvalidRel.
import ABSL;return !this.phoneInvalidRel;
In the runtime, when I enter “A” in mobile phone field and save, first the BeforeSave event is triggered,
And then the onSave Validation is called.
The above implementation could only cover the scenario that end user directly changes the mobile phone number which is technically modelled in BO BusinessPartnerRelationship. There is another possibility that end user will also changes the field on Root node of BO BusinessPartner, as a result the same logic should be done again on BO BusinessPartner as well.
BeforeSave implementation on BusinessPartner Root node:
import ABSL;var phone;var common = this.Common.GetFirst();common.phoneInvalid = false;if( !this.CurrentDefaultIsContactPersonFor.IsSet())
return;var currentDefaultContact = this.CurrentDefaultIsContactPersonFor;var BPRelationship = currentDefaultContact.BusinessPartnerRelationship;if ( !BPRelationship.ContactPerson.IsSet())
return;var contact = BPRelationship.ContactPerson;if( !contact.ContactPersonWorkplaceAddressInformation.IsSet())
return;var workplaceAddress = contact.ContactPersonWorkplaceAddressInformation;if( !workplaceAddress.ContactPersonWorkplaceAddress.DefaultMobilePhone.IsSet())
return;phone = workplaceAddress.ContactPersonWorkplaceAddress.DefaultMobilePhone;if( phone.FormattedNumberDescription.IsInitial())
return;if( phone.FormattedNumberDescription.FindRegex("1\\d{10}") < 0){
// raise "Invalid mobile phone number!"; common.phoneInvalid = true;
raise Error_phone_msg.Create("E", phone.FormattedNumberDescription );}
OnSave Validation on BusinessPartner Root node:
import ABSL;var common = this.Common.GetFirst();return !common.phoneInvalid;
要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24475491/viewspace-2724394/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 如何自定義 SAP UI5 字串型別輸入欄位的校驗邏輯試讀版UI字串型別
- 如何給 SAP ABAP ALV 報表的修改功能新增自定義校驗邏輯試讀版
- SAP UI5 Currency 資料型別的校驗邏輯分析UI資料型別
- 如何在SAP Cloud for Customer自定義BO中建立訪問控制Cloud
- SAP Commerce Cloud Product Review 的新增邏輯CloudView
- 如何給 SAP Fiori Elements 應用的欄位新增 value help
- 如何給 SAP Fiori Elements 應用新增自定義按鈕
- pydantic 欄位欄位校驗
- 使用程式碼給 SAP UI5 XML 檢視新增自定義 CSSUIXMLCSS
- django 自定義登入驗證邏輯Django
- SAP Spartacus UI 透過 HTTP Interceptor 給請求新增 Authorization 欄位的原始碼分析UIHTTP原始碼
- SAP CRM和Cloud for Customer的擴充套件欄位後設資料Cloud套件
- SAP 電商雲 Spartacus UI 同 SAP Customer Data Cloud 的整合UICloud
- 如何在 SAP Spartacus 產品明細頁面新增自定義 UIUI
- SAP Cloud for Customer的Mashup位於CustomPane裡Cloud
- Spring Cloud Gateway自定義Token校驗過濾器SpringCloudGateway過濾器
- SAP不同的產品是如何支援使用者建立自定義欄位的
- element-ui自定義表單校驗規則及常用表單校驗UI
- SAP UI5 sap-ui-core.js的載入邏輯UIJS
- 如何給SAP Cloud ConnectorRegion列表中新增新的RegionCloud
- SAP Cloud for Customer如何實現從標準UI到自開發UI的跳轉CloudUI
- 如何把SAP CRM WebClient UI上某個欄位高亮加粗顯示WebclientUI
- 無法在SAP Fiori UI上新增擴充套件欄位?原因可能就在這裡UI套件
- 如何自行給指定的SAP OData服務新增自定義日誌記錄功能
- AI剪輯和自定義UI,打造更智慧的剪輯體驗AIUI
- 織夢後臺新增自定義欄位樣式修改
- 如何使用SAP Cloud for Customer裡的Data SourceCloud
- 如何下載SAP Cloud for Customer UI技術模型的XML原始碼到本地CloudUI模型XML原始碼
- Python 中 sorted 如何自定義比較邏輯Python
- SAP 電商雲 Spartacus UI 同 SAP Customer Data Cloud 整合執行時的 apiUICloudAPI
- SAP Cloud for Customer的前世今生Cloud
- 如何查詢SAP Cloud for Customer UI頁面對應的技術模型明細CloudUI模型
- Request 增加自定義欄位的方式
- SAP Cloud for Customer框架是如何使用JavaScript Promise的Cloud框架JavaScriptPromise
- SAP Commerce Cloud 新一代 UI Spartacus 和 Customer Data cloud 的整合CloudUI
- SAP Cloud for Customer UI Designer裡如何消費Object Value Selector(OVS)CloudUIObject
- SAP Cloud for Customer的Account Team裡的role如何配置Cloud
- Google Cloud IAM中新增自定義域名GoCloud