show / hide menu

Validate Vacation date

The employee should apply for leave and get that approved before taking the vacation leave. So when a employee is applying for a vacation, the date of leave should not be less than the current date. The company also has a restriction that the employee should not take any company restricted date in the vacation.

Logical Flow:

When the user selects a date in the “Vacation Days Requested” grid, we need to check if the date selected is less than or equal to current date.

We can use the Expression Builder to create the rule.

Step 1:
1Click on the dynamic Grid to select the control
2 Click on the “Rules Panel” to display the rules panel
3Click on the “Create New Rule” button to create a new rule

Step 2:
1 The new rule will be created with the default name.
2 Click on the edit button to rename the rule name.
3 Click on the “+” button in the Decisions section to to create a new decision.

Step 3: In this step we are going to add a decision to check if the current column is 2 (date) and if the date selected is less than current date

  1. Click on the controls in the first listbox. This will display all the controls in the current form in the next listbox.
  2. Select the control named “dgVacation” to select the dynamic grid. This will display all the properties of the grid control.
  3. Select the ColIndex property, which will let us know the current column in focus in the grid.
  4. Click on the add button which will add the expressions section. Then click on the “=” button to add the operator to the expression.
  5. Click on the operator “=” to display the “Add LHS” and “Add RHS” buttons.
  6. Clicking on the “Add RHS” button will insert a new textbox right side of the operator.
  7. Type the value 2 in the “RHS” textbox.
    Now we have a expression that checks if the current row is the first column

Once we complete the rules expression it will have a look as shown below. The expression will read
“dgVacation.ColIndex=1 & GridGetValue(dgVacation,dgVacation.RowIndex,2)<=GlobalVariable(ServerDate)”

If it is less than current date,

  • Then display a message “Date should be greater than current date, please select another date”.
  • The grid column “Status” should be set to 0, so that the red label is displayed as a indication of invalid date.
  • The insert row option for the grid should be disabled.

Click on the “+” button in the next to the Decision we just created. This will add actions under this section. Add the expression as shown in the screen below. The expression will read “MessageBox(“Date should be greater than current date, please select another date”)”

Click on the “+” button in the next to the Decision we created. This will add another action under this section. Add the expression as shown in the screen below. The expression will read “GridSetValue(dgVacation,dgVacation.RowIndex,4,0)”

Click on the “+” button in the next to the Decision we created. This will add another action under this section. Add the expression as shown in the screen below.The expression will read “dgVacation.PreventNewRow=true”

if its a date greater than current date,

  • Then we have to pass the date to the textbox “txtDate”
  • When the date is passed to the textbox “txtDate” then that will execute the DataSource “Select Restricted Date“.

Once we complete the rules expression it will have a look as shown below. The expression will read
“dgVacation.ColIndex=1 & GridGetValue(dgVacation,dgVacation.RowIndex,2)>=GlobalVariable(ServerDate)”

The expression in the action below this decision will read as
Action 1 : txtDate.Value = GridGetValue(dgVacation,dgVacation.RowIndex,2)
Action 2 : dgVacation.PreventNewRow=false
Action 3 : GridSetValue(dgVacation,dgVacation.RowIndex,4,0)

So this rule when completed will display as:

DynamicGrid dgVacation – Column Value Change Event fill trigger the following rule

Rule 1 : dgVacation.ColIndex=2 & GridGetValue(dgVacation,dgVacation.RowIndex,2) <= GlobalVariable(ServerDate)
( If the current column in the dynamic grid is 1 and the selected date is less than current date )
Action 1 : dgVacation.PreventNewRow=true (Disable the Insert New Row Link button )
Action 2 : GridSetValue(dgVacation,dgVacation.RowIndex,4,0)
(Display a red label in the row to indicate a invalid date selected )

Action 3 : MessageBox(“Date should be greater than current date, please select another date”) (Show a alert that the date selected is wrong)

Rule 2 : dgVacation.ColIndex=2 & GridGetValue(dgVacation,dgVacation.RowIndex,2)>=GlobalVariable(ServerDate)
( If the current column in the dynamic grid is 1 and the selected date is greater than current date )
Action 1 : txtDate.Value = GridGetValue(dgVacation,dgVacation.RowIndex,2)
(pass the date to the hidden textbox which will trigger another rule )

Rule 3 : dgVacation.ColIndex=3 ( If the current column is the hours )
Action 1 : txtTotalVTR.Value=GridSum(dgVacation,3,false)( Display the sum in the textbox below )

The textbox txtDate will trigger the ExecuteCommand of the Select Restricted Date. We need to make sure that the following actions are added to the same rule before the command is executed.
Action 1 : dgVacation.PreventNewRow=false (enable the Insert New Row Link button )
Action 2 : Clear(txtDateId) (Clear the value in the textbox txtDateId )
Action 2 : GridSetValue(dgVacation,dgVacation.RowIndex,4,1) (Display a green label in the row which will be overridden if it is a restricted date)

We will need to add a rule for the textbox txtDateId to see if there is a positive number returned from the server for this date criteria. If it returns a valid date id, then the user has selected a invalid date. So the rule should read as following.

Rule 1 : txtDateId.Value > 0
( If the command execution has returned a valid Id )
Action 1 : dgVacation.PreventNewRow=true (Disable the Insert New Row Link button )
Action 2 : GridSetValue(dgVacation,dgVacation.RowIndex,4,0) (Display a red label in the row to indicate a invalid date selected )
Action 3 : MessageBox(“Selected date is restricted, please select another date”) (Show a alert that the date selected is wrong)