Skip to main content

GDA-SMDS : Conditional Check Implementation in Ruleset Table - Solution LLD

Created by Srikant Sahoo, last modified on Feb 10, 2025

  1. What is the conditional_check column in the ruleset table, and why is it necessary?
    All rules are stored in the smds_generic_country_rules table. However, not all rules are straightforward in CMD, and some rules depend on others. To effectively manage these rule dependencies, it is essential to include the conditional_check column within the same table.
  2. How to interpret the conditional_check values?
    Currently, there are two types of conditional_check, each with distinct meanings:
    1. OR separator | - This indicates that both rules are optional, but at least one must be provided.
    2. AND separator & - This signifies that the second rule is dependent on the first. In other words, the second rule applies only when the first rule is satisfied.
  3. Let's explore some examples of conditional_check implementations below:
    1. Street Number mandatory requirement CMD1-5948 -Customer and facility street name mandatory In Progress
country_iso_codefield_typemandatory_indcheck_typecheck_exact_locheck_max_hicheck_maskcheck_mask_expconditional_check
OMSTREET_NAMEXFor Oman, the street name is mandatory.^[a-zA-Z0-9.,:;$%&+\]\[*\"( )'\/^\-]{0,36}$
OMPO_BOXFor country Oman, PO Box is optional and length must not be more than 10 characters.^[a-zA-Z0-9.,:;$%&+\]\[*\"( )'\/^\-]{0,10}$

Explanation - Here for Oman the STREET_NAME is mandatory and PO_BOX is optional.

STREET_NAMEPO_BOXIs Valid?
ABCYES
ABCNO
ABCABCYES
NO

b. Any other country - CH, IN, PK etc

country_iso_codefield_typemandatory_indcheck_typecheck_exact_locheck_max_hicheck_maskcheck_mask_expconditional_check
LTSTREET_NAMEXFor Lithuania, either Street Name or P.O Box is mandatory.^[a-zA-Z0-9.,:;$%&+\]\[*\"( )'\/^\-]{0,36}$STREET_NAME | PO_BOX
LTPO_BOXFor Lithuania, either Street Name or P.O Box is mandatory.^[a-zA-Z0-9.,:;$%&+\]\[*\"( )'\/^\-]{0,10}$STREET_NAME | PO_BOX

Explanation - Here for Lithunia or any other countries, both the STREET_NAME and PO_BOX is optional. But the user needs to enter either one of them.

STREET_NAMEPO_BOXIs Valid?
ABCYES
ABCYES
ABCABCYES
NO

c. AE PO_BOX mandatory requirement - CMD1-4114 -Make UAE PO box and phone number mandatory Done

country_iso_codefield_typemandatory_indcheck_typecheck_exact_locheck_max_hicheck_maskcheck_mask_expconditional_check
AEPO_BOXX2100For country U. A. E., PO Box is mandatory and length must be from 1 to 10 characters.^[a-zA-Z0-9.,:;$%&+\]\[*\"( )'\/^\-]{0,10}$
AESTREET_NAMEXFor UAE, the street name is mandatory.^[a-zA-Z0-9.,:;$%&+\]\[*\"( )'\/^\-]{0,36}$

Explanation - Here for UAE both STREET_NAME and PO_BOX are mandatory. The user needs to enter both of them.

STREET_NAMEPO_BOXIs Valid?
ABCNO
ABCNO
ABCABCYES
NO

d. US requirement - CMD1-4492 -Make US street number mandatory Done

country_iso_codefield_typemandatory_indcheck_typecheck_exact_locheck_max_hicheck_maskcheck_mask_expconditional_check
USSTREET_NUMBERXPlease enter the PO Box. If the PO Box is blank, the Street Number and the Street Name must be entered.STREET_NUMBER | PO_BOX
USSTREET_NAMEXPlease enter the PO Box. If the PO Box is blank, the Street Number and the Street Name must be entered.^[a-zA-Z0-9.,:;$%&+\]\[*\"( )'\/^\-]{0,36}$STREET_NAME | PO_BOX
USPO_BOXPlease enter the PO Box. If the PO Box is blank, the Street Number and the Street Name must be entered.^[a-zA-Z0-9.,:;$%&+\]\[*\"( )'\/^\-]{0,10}$**STREET_NAME | PO_BOXSTREET_NUMBER** WIP
STREET_NUMBERSTREET_NAMEPO_BOXIs Valid?
ABCABCYES
ABCABCYES
ABCABCABCYES
ABCNO
ABCNO
ABCYES
ABCABCYES
NO

STREET_NUMBER and STREET_NAME are mandatory only if PO_BOX is not entered.
If pobox is entered no need to enter anything.

e. Brazil - CMD1-5441 -Brazil tax rule change Done

country_iso_codefield_typemandatory_indcheck_typecheck_exact_locheck_max_hicheck_maskcheck_mask_expconditional_check
BRTAXNO2XWIPA11For country Brazil, Tax Number 2 field (CPF) should be 11 numeric digits, format NNNNNNNNNNN. Also, either CNPJ (BR1) or CPF (BR2) is mandatory for Brazil customers.^[0-9]{11}$TAXNO1 | TAXNO2
BRTAXNO1A14For Country Brazil, Tax Reference field (CNPJ) length must be 14 numeric digits, format NNNNNNNNNNNNNN. Also, either CNPJ (BR1) or CPF (BR2) is mandatory for Brazil customers.^[0-9]{14}$(TAXNO1 & TAXNO3 & TAXNO4 & TAXNO5) | TAXNO2 WIP
BRTAXNO509For country Brazil, Tax Number 5 field (SUFRAMA ID) must not be more than 9 digits. Also Tax Number 5 field is optional when TAX Number 1 is entered.^[0-9]{0,9}$TAXNO1 & TAXNO5
BRTAXNO4C018For country Brazil, Tax Number 4 field (Municipal Tax) must not be more than 18 digits. Also, Tax Number 4 field is optional when TAX Number 1 is entered.^[0-9]{0,18}$TAXNO1 & TAXNO4
BRTAXNO3XC114For country Brazil, Tax Number 3 field (State Tax) must not be more than 14 digits or ‘ISENTO’. Also, Tax Number 3 field is mandatory when TAX Number 1 is entered.^ISENTO$|^[0-9]{1,14}$TAXNO1 & TAXNO3
BRSTREET_NAMEXFor Brazil, either Street Name or P.O Box is mandatory.^[a-zA-Z0-9.,:;$%&+\]\[*\"( )'\/^\-]{0,36}$STREET_NAME | PO_BOX
BRPO_BOXFor Brazil, either Street Name or P.O Box is mandatory.^[a-zA-Z0-9.,:;$%&+\]\[*\"( )'\/^\-]{0,10}$STREET_NAME | PO_BOX

Here either of TAXNO1 or TAXNO2 needs to be entered.

TAXNO5, TAXNO4, TAXNO3 are dependent on TAXNO1 i.e only if TAXNO1 is entered then the TAXNO5, TAXNO4 and TAXNO3 are applicable.
And since there is a mandatory indicator in TAXNO3, it means it needs to be entered by the user whenever TAXNO1 is present, whereas TAXNO4 and TAXNO5 are optional even though both are dependent on TAXNO1.

If someone enters TAXNO2 then they can choose to not enter anything else since there are no other dependent rules related to it.

Future enhancements

  • (TAXNO1 & TAXNO3 & TAXNO4 & TAXNO5) | TAXNO2 - Complex strings in conditional checks
  • Merging the tables of facility and ruleset into a single table, can include rules for contact etc.

f. Thailand - CMD1-5224 -Enable branch ID for Thailand customers Done

country_iso_codefield_typemandatory_indcheck_typecheck_exact_locheck_max_hicheck_maskcheck_mask_expconditional_check
THTAXNO1A13For Country Thailand, Tax Reference field length must be 13 numeric digits,format NNNNNNNNNNNNN Ex: 1234567890987^[0-9]{13}$|^ZZ$
THBIDXFor Thailand, the Branch ID is mandatory if the Thailand tax ID is entered and the format is ‘NNNNN’. For example, “00000”, “00001”, … “99999” etc.”^\d{5}$TAXNO1 & BID
THSTREET_NAMEXFor Thailand, either Street Name or P.O Box is mandatory.^[a-zA-Z0-9.,:;$%&+\]\[*\"( )'\/^\-]{0,36}$STREET_NAME | PO_BOX
THPO_BOXFor Thailand, either Street Name or P.O Box is mandatory.^[a-zA-Z0-9.,:;$%&+\]\[*\"( )'\/^\-]{0,10}$STREET_NAME | PO_BOX

Here BID is applicable only when TAXNO1 is entered. And BID is mandatory only when it TAXNO1 is entered. If there is no TAXNO1 then BID cannot be added to the customer.

g. ROC for Malaysia ( WIP ) - CMD1-6090 -Malaysia ROC number / Company Registration Number mandatory To Do

Approach 1

country_iso_codefield_typemandatory_indcheck_typecheck_exact_locheck_max_hicheck_maskcheck_mask_expconditional_checkisExternalCheckApplicable, excludeRule
MYCRN140For country Malaysia CRN can be between 1 to 40 in length.^[a-zA-Z0-9.,:;$%&+\]\[\*\"\(\)\/'\^\-\s]{1,40}$|^ZZ
MYCORX312For Country Malaysia, Customer reference field length can be from 3 digit to 12 digits, format N(1 to 10 times)-L (Where N denotes number and L denotes Letter) or LLNNNNNNN-L^[0-9]{1,10}[-]{1}[A-Z]{1}$|^[A-Z]{2}[0-9]{7}[-]{1}[A-Z]{1}$^ZZ$ROC | COR
MYROCA12For Country Malaysia, Register Of Company length must be 12 digit. Format NNNNNNNNNNNN^[0-9]{12}$ROC | COR
MYREGIONFor country Malaysia, State field is mandatory.^[A-Z0-9\&\'\- ]{1,50}$REGION & (ROC | COR)}
MYSTREET_NAMEXFor Malaysia, either Street Name or P.O Box is mandatory.^[a-zA-Z0-9.,:;$%&+\]\[*\"( )'\/^\-]{0,36}$STREET_NAME | PO_BOX
MYPO_BOXFor Malaysia, either Street Name or P.O Box is mandatory.^[a-zA-Z0-9.,:;$%&+\]\[*\"( )'\/^\-]{0,10}$STREET_NAME | PO_BOX

Approach 2 - (Preferred)

MYROC | CORXFor Malaysia, either of ROC(Registration of Company) or COR(Customer’s own Reference number) reference is mandatory.ROC | COR

API

/validate-rules -

Here the ROC | COR rule can be read by the API and UI and based on the conditional check the rules can be checked.

// Psuedo Code

if(Ruleset["ROC|COR"].isMandatory){ // logic here to return the formatCheckDescription of either ROC | COR is mandatory if the cases does not satisfy

if ( !CMDApplicationConfig.anyMatch(CustomerRegion == IgnoreCase(configRegion)){ // check here if either ROC or COR is entered/not empty // if it is empty then throw formatCheckDescription error of rule "ROC | COR" // if it is entered then pass the validation } else { // else pass the validation if Region is Sabah or Sarawak // No need to write any logic here } }

BBU scenario - Address template on region/city change should throw an error of ROC | COR.
Similar above logic can be placed to validate whether the references are present in the customer or not, otherwise, the user needs to first enter the reference then update the address.

MatrixROCCORResult
Other regionsYVALID
Other regionsYYVALID
Other regionsINVALID
Other regionsYVALID
SABAH/SARAWAKYVALID?(Doubt)
SABAH/SARAWAKYYVALID
SABAH/SARAWAKINVALID
SABAH/SARAWAKYVALID

Requirement analysis of ROC & COR

  1. For MY it’s COR whose length is 12 and also there is an existing regex. Its not CRN as mentioned in Epic.
  2. As per the email thread
    ROC – 12 digits NNNNNNNNNNNN
    Customer’s Own Reference Number – NNNNNN-X format.

Below is a dynamic approach for calibrating the rules in CMD - This approach can be implemented when we work on the next ruleset requirement.
Due to current limited bandwidth we are going with the above mentioned ROC | COR implementation.

Expected JSON Structure

[

    {
"fieldType": "PO_BOX",
"validation": {
"rules": [
{
"type": "ANY_OF",
"fields": ["STREET_NAME"],
"message": "For Malaysia, either Street Name or P.O Box is mandatory."
}
],
"formatCheck": {
"pattern": "^[a-zA-Z0-9.,:;$%&+\\]\\[*\\\"( )'\\/^\\-]{0,10}$",
"description": "For Malaysia, P.O Box must be a maximum of 10 characters."
}
},
"properties": {
"isMandatory": false,
"isDependent": false,
"isApplicable": true,
"isExternalCheckApplicable": false
}
},
    {
"fieldType": "STREET_NAME",
"validation": {
"rules": [
{
"type": "ANY_OF",
"fields": ["PO_BOX"],
"message": "For Malaysia, either Street Name or P.O Box is mandatory."
}
],
"formatCheck": {
"pattern": "^[a-zA-Z0-9.,:;$%&+\\]\\[*\\\"( )'\\/^\\-]{0,36}$",
"description": "For Malaysia, Street Name must be a maximum of 36 characters."
}
},
"properties": {
"isMandatory": true,
"isDependent": false,
"isApplicable": true,
"isExternalCheckApplicable": false
}
},
    {
"fieldType": "ROC",
"validation": {
"rules": [
{
"type": "DISABLES",
"fields": ["REGION"],
"condition": { "values": ["SARAWAK", "SABAH"] },
"message": "ROC is not applicable when REGION is SARAWAK or SABAH."
},
{
"type": "DISABLES",
"fields": ["CITIES"],
"condition": { "values": ["SARAWAK", "SABAH"] },
"message": "ROC is not applicable when REGION is SARAWAK or SABAH."
}
],
"formatCheck": {
"pattern": "^[0-9]{12}$",
"description": "For Malaysia, Register Of Company (ROC) must be 12 numeric digits."
}
},
"properties": {
"isMandatory": true,
"isDependent": false,
"isApplicable": true,
"isExternalCheckApplicable": false
}
},
    {
"fieldType": "COR",
"validation": {
"rules": [
{
"type": "MANDATORY_IF",
"condition": { "field": "REGION", "values": ["SARAWAK", "SABAH"] },
"message": "COR is mandatory when REGION is SARAWAK or SABAH."
}
],
"formatCheck": {
"pattern": "^[0-9]{1,10}[-]{1}[A-Z]{1}$|^[A-Z]{2}[0-9]{7}[-]{1}[A-Z]{1}$|^ZZ$",
"description": "For Malaysia, COR must follow one of the formats: N(1-10)-L, LLNNNNNNN-L, or 'ZZ'."
}
},
"properties": {
"isMandatory": false,
"isDependent": false,
"isApplicable": true,
"isExternalCheckApplicable": false
}
},
        {
"fieldType": "BR2",
"validation": {
"rules": [
{
"type": "ANY_OF",
"fields": ["BR1"],
"message": "Either BR1 or BR2 must be provided."
},
{
"type": "MANDATORY_IF",
"condition": { "field": "BR2", "valueExists": true },
"fields": ["BR3", "BR4"],
"message": "If BR2 is provided, BR3 and BR4 must also be provided."
},
{
"type": "OPTIONAL_IF",
"condition": { "field": "BR2", "valueExists": true },
"fields": ["BR5"],
"message": "If BR2 is provided, BR5 is optional."
},
{
"type": "DISABLES",
"fields": ["BR6", "BR7"],
"condition": { "field": "BR2", "valueExists": true },
"message": "If BR2 is provided, BR6 and BR7 cannot be entered."
}
],
"formatCheck": {
"pattern": "^[0-9]{14}$",
"description": "For Country Brazil, Tax Reference field (CNPJ) must be 14 numeric digits (NNNNNNNNNNNNNN)."
}
},
"properties": {
"isMandatory": false,
"isApplicable": true,
"isDependent": false,
"isExternalCheckApplicable": true
}
},
    {
"fieldType": "BR2",
"validation": {
"rules": [
{
"type": "ANY_OF",
"fields": ["BR1"],
"message": "Either BR1 or BR2 must be provided."
}
],
"formatCheck": {
"pattern": "^[0-9]{11}$",
"description": "For Country Brazil, Tax Number 2 (CPF) must be 11 numeric digits (NNNNNNNNNNN)."
}
},
"properties": {
"isMandatory": false,
"isApplicable": true,
"isDependent": false,
"isExternalCheckApplicable": true
}
},
    {
"fieldType": "BR3",
"validation": {
"formatCheck": {
"pattern": "^ISENTO$|^[0-9]{1,14}$",
"description": "For Country Brazil, Tax Number 3 (State Tax) must not exceed 14 digits or the value 'ISENTO'."
},
"rules": [
{
"type": "MANDATORY_IF",
"condition": { "field": "BR1", "valueExists": true },
"message": "Tax Number 3 is mandatory when BR1 is provided."
}
]
},
"properties": {
"isMandatory": true,
"isApplicable": true,
"isDependent": true,
"isExternalCheckApplicable": true
}
},
    {
"fieldType": "BR4",
"validation": {
"formatCheck": {
"pattern": "^[0-9]{0,18}$",
"description": "For Country Brazil, Tax Number 4 (Municipal Tax) must not exceed 18 digits."
},
"rules": [
{
"type": "OPTIONAL_IF",
"condition": { "field": "BR1", "valueExists": true },
"message": "Tax Number 4 is optional when BR1 is provided."
}
]
},
"properties": {
"isMandatory": false,
"isApplicable": true,
"isDependent": true,
"isExternalCheckApplicable": true
}
}

]

// Example rule enums

  • ANY_OF
  • ALL_OF
  • DISABLES
  • ENABLES
  • VALUE
  • IS_MANDATORY
  • IS_NOT_MANDATORY
  • FIELDS
  • ANY_OF_FIELDS
  • ALL_OF_FIELDS
  • ANY_OF_VALUES
Was this page helpful?