◷ Reading Time: 6 minutes
This Address Book Validation project includes contacts with name (first and last), address (address line, postcode, state), and address type. There are mandatory fields to validate.and error messages will be shown accordingly.
We used Natural Language to write the rules and these are easy to read and understand.
How to Run the Address Book Validation Project
Use Data Composer to run the project. Samples are supplied in the data folder of the project.
Open the Natural Language file StateRules.xml from the Project Explorer menu.

Click on the Start Debugging option from he main toolbar menu.

This opens the Data Feed Providers modal. From the Provider Type section, select the Data Composer option from the Source dropdown.

Now select the ellipsis button to the right of the Data field to open the Data Composer modal. From this modal select the open button from the toolbar.
Now in the file explorer, navigate to the Writing Business Rules project folder and inside the Data folder, select the Sample1.dc.json file.
<Project folder>\Writing-Business-Rules\Data

You will now see FlexRule.json in the left side view of the Data Composer modal. On the right side of the modal under the Parameters section, enter Person as the Name and click OK.

This returns you to the Data Feed Provider modal.
From here, select Object by Data Composer from the Input drop-down within the Execution Options section and click OK.

This returns you to the main Designer view. Now, from the main toolbar click the Step In option (blue forward arrow) to go step-by-step through the debug.

A modal ‘The execution has complete with no errors’ will display. This means the logic executed successfully without any exceptions.
After execution an Error ‘State cannot be empty’ will display in the Notifications view defining certain expected information was missing while executing the logic.

This is expected from the logic in line 20 of the Natural Language logic document where the State the person resides is not supplied:
when State is not blank
/* Write your condition here */
Value of (Person?.Address?.State) is blank == false
then
otherwise
/* Write your satisfied actions here */
Write ('State cannot be empty') as ('Error')
end
Address Book Validation project steps
1. Define the Fact Concept and variables: AddressBook.xml
Create a Fact Concept document defining the variables, such as name and address, and link them according to their connections.
Add a Fact for Person containing four members, Name, Family, Phone and Address. Create a second fact, Address and link to the Address member of Person. This has five members, Line 1, Line 2, State, Postcode and Type. The Type member has a linked Option called Address Type with three members, Home, Work and Other.
The Fact and Options members are the variables for the project.

2. Write the address book-specific rules: StateRules.xml
Create a Natural Language document called StateRules.xml and add these rules to this Natural Language.
when Set 1: People in VIC and NSW require to provide fullname
State is not blank and
Fullname is required
end
when Fullname is required
/* Write your condition here */
State (Person.Address.State) is any of (['VIC', 'NSW']) and
(
Value of (Person.Name) is blank or
Value of (Person.Family) is blank
)
then
/* Write your satisfied actions here */
Write ('For VIC and NSW full name is required') as ('Error')
end
when State is not blank
/* Write your condition here */
Value of (Person?.Address?.State) is blank == false
then
otherwise
/* Write your satisfied actions here */
Write ('State cannot be empty') as ('Error')
end

Now create a second Natural Language document called CoreLibrary.xml.
In the Properties menu for StateRules.xml under the Definitions section, select the ellipsis button in the Includes field to open the Link Natural modal.
Select the Add New Natural option, locate the CoreLibrary.xml and select OK to connect the CoreLibrary file and use the functions there.

3. Write core library rules for reuse: CoreLibrary.xml
Add these rules to the CoreLibrary.xml document that can be reused (use as a library).
when Value of {name} is blank
name==null or name==''
end
when Value of {name} is not blank
Value of (name) is blank == false
end
when State {st} is any of {list}
list|contains(st)
end
when State {st} is not any of {list}
State (st) is any of (list) == false
end
when Write {msg} as {type}
/* no condition, just writing notification */
then
notificationWrite('Error', msg, type)
end

Download the project
Use the attachment at the end of the page to download the sample project.