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:
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
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,
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,
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)