如何给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;
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 数组:这个循环可以转懵很多人!
- 企业远程办公视频会议系统EasyRTC-SFU下侧边栏边框超限问题如何解决?
- 编写高质量可维护的代码:数据建模
- 新版企业远程办公视频通话系统EasyRTC-SFU,如何解决用户登录信息更新不及时的问题?
- 服务应用突然宕机了?别怕,Dubbo 帮你自动搞定服务隔离!
- 33.Python字符串方法find以及与序列解包的技巧结合
- 代码审计从0到1 —— Centreon One-click To RCE
- 一文带你深扒ClassLoader内核,揭开它的神秘面纱!
- 小知识:OGG的TRANLOGOPTIONS MINEFROMACTIVEDG参数
- oracle转postgreSQL修改点
- 重学数据结构(三、队列)
- Jmeter系列(68)- BeanShell 内置变量 prev
- 聊聊java中的哪些Map:(六)ConcurrentHashMap源码分析
- 任意文件包含漏洞的绕过方式
- XXE实体注入漏洞详解