This guide explains how to set up a script to correctly determine a customer's date of birth if it is partially specified or refers to a period before 1950. As an example, we will consider converting the year from 2047 to 1947 if the customer specifies the date as “June 15, 47.”
Create a Question block.
Enter the following in the Message field: Enter your date of birth.
Create an Expression block.
Draw an arrow from the Question block to the Expression block.
Configure the arrow in the Expression block:
5.1. Data type: NLU.
5.2. Agent: select the previously created NLU agent.
5.3. Intent: any of the created ones.
5.4. Entity: time.
5.5. Variable: bday.
Enter the code for the Expression block:
6.1. Click the Open Editor button. An input window will open.
6.2. Enter the code:
$bday = dt.format($bday, ‘y-MM-dd’)
6.3. Click Save.
Drag the arrow from the Expression block to the Condition block and configure it:
7.1. Data type: Date.
7.2. Date value: Any.
7.3. Variable name: bday.
Draw two arrows from the Condition block:
8.1. First arrow from the Condition block to the Information block:
{bday} < 2030-01-01.8.2. Second arrow from the Condition block to the Expression block:
{bday} >= 2030-01-01.Enter the following in the Message field of the Information block: Normal entry {bday}.
Configure the parameters of the Expression block:
10.1. Click the Open editor button. An input window will open.
10.2. Enter the code:
$bdaysplit = str.split($bday, “-”);
$year = $bdaysplit.get(0);
$month = $bdaysplit.get(1);
$day = $bdaysplit.get(2);
$year = str.replace($year, “20”, “19”);
$bday = str.join([$year, $month, $day], “-”);
10.3. Click Save.
Record with correction {bday}.Create a test widget with the previously created script. Instructions for creating it are available in the article Creating a test widget.
Test the script in the test widget:
1965-05-15. Make sure it is saved without changes.June 15, 47. Check that it is converted to 1947-06-15.