CastInvalidCould not cast from ES_Working_Hours_Record to Time. Details: CastInvalid

Hi all,

I'm creating a record hours system app, I made the interface that lets the user insert his start time, and leaving time then, the system should calculate the duration between start time and leaving time.

the problem is when I finished the code, I got a problem which is A null parameter has been passed.

then I've tried to solve this issue by adding this before the first if sentence:

 if(
a!isnullOrEmpty(ri!ES_Working_Hours_Record),
null,
hour(ri!ES_Working_Hours_Record)
)

but I have a casting problem now, I got this: Interface Definition: Expression evaluation error at function 'hour' [line 36]: Could not cast from ES_Working_Hours_Record to Time. Details: CastInvalidCould not cast from ES_Working_Hours_Record to Time. Details: CastInvalid

this is the code: 

a!formLayout(
label: "Working Hours Record",
contents: {
a!columnsLayout(
columns: {
a!columnLayout(
contents: {
a!dateTimeField(
label: "Start Time",
labelPosition: "ABOVE",
value: ri!ES_Working_Hours_Record.StartTime,
saveInto: ri!ES_Working_Hours_Record.StartTime
)
}
),
a!columnLayout(
contents: {
a!dateTimeField(
label: "Leaving Time",
labelPosition: "ABOVE",
value: ri!ES_Working_Hours_Record.LeavingTime,
saveInto: ri!ES_Working_Hours_Record.LeavingTime
)
}
)
}
),
a!richTextDisplayField(
labelPosition: "COLLAPSED",
value: {
a!richTextItem(
text: {
if(
a!isnullOrEmpty(ri!ES_Working_Hours_Record),
null,
todate(hour(ri!ES_Working_Hours_Record))
),
hour(ri!ES_Working_Hours_Record.LeavingTime - ri!ES_Working_Hours_Record.StartTime),
" hours",

if(

hour(ri!ES_Working_Hours_Record.LeavingTime - ri!ES_Working_Hours_Record.StartTime) = "8",

"
Working hours are complete",
if(
and(8 > hour(ri!ES_Working_Hours_Record.LeavingTime - ri!ES_Working_Hours_Record.StartTime) > 0),
"
Working hours are not complete",
if(
hour(ri!ES_Working_Hours_Record.LeavingTime - ri!ES_Working_Hours_Record.StartTime) = 0,
" insert working hours correctly please",
" working hours passed limit"
)
)
)
},
size: "STANDARD",
style: {
"STRONG"
}
)
}
)
},
buttons: a!buttonLayout(
primaryButtons: {
a!buttonWidget(
label: "Submit",
submit: true,
style: "PRIMARY"
)
},
secondaryButtons: {
a!buttonWidget(
label: "Cancel",
value: true,
saveInto: ri!cancel,
submit: true,
style: "NORMAL",
validate: false
)
}
)
)

  Discussion posts and replies are publicly visible