Skip to main content
October 22, 2022
Question

CastInvalidCould not cast from ES_Working_Hours_Record to Time. Details: CastInvalid

  • October 22, 2022
  • 3 replies
  • 1 view

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
)
}
)
)

3 replies

stefanhelzle0001
Brainy
October 22, 2022

I think that the code you mentioned just will not work.

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

ri!ES_Work_Hours_Record is a data structure, but no datetime or time value. And then trying to cast this into a date will also not help.

Next time please use this to insert code.

alim9650Author
October 22, 2022

so what should I do to solve this issue? 

stefanhelzle0001
Brainy
October 22, 2022

The same as you did two lines below. Use one of the fields of your data structure.