0

I am trying to display a particular string using an if else statement based on the value of a date/time object.

I am using a formula editor which checks for syntax and I get no problems, however when the formulas is parsed in the application I get blanks where the condition should be met.

Here is my formula:

if (System.Convert.ToInt32(rpt.Fields["AppointmentResourceLink.Appointment.Patient.DateDied"].Value)>0)
{
 return System.Convert.ToString(rpt.Fields["AppointmentResourceLink.Appointment.Patient.FirstName"].Value) + " " + System.Convert.ToString(rpt.Fields["AppointmentResourceLink.Appointment.Patient.LastName"].Value) + '\n' + "Deceased: " + System.String.Format("{0:dd/MM/yyyy}",rpt.Fields["AppointmentResourceLink.Appointment.Patient.DateDied"].Value);
}
else
{
  return System.Convert.ToString(rpt.Fields["AppointmentResourceLink.Appointment.Patient.FirstName"].Value) + " " + System.Convert.ToString(rpt.Fields["AppointmentResourceLink.Appointment.Patient.LastName"].Value);
 }

The Formula editor allows conversion to different data types and I've tried revising the formula with the returned value as Boolean but this doesn't work either.

Thanks

Aus Gamer
  • 1
  • 1

2 Answers2

4

Convert.ToInt32 method doesn't support the conversion from DateTime to int.

https://learn.microsoft.com/en-ca/dotnet/api/system.convert.toint32?view=netframework-4.7.1#System_Convert_ToInt32_System_DateTime_

Ukjin
  • 41
  • 4
0

This is what worked:

// ListFields();

try { if (System.Convert.ToInt32(System.String.Format("{0:yyyy}",rpt.Fields["AppointmentResourceLink.Appointment.Patient.DateDied"].Value))>1) return "Deceased date: " + System.String.Format("{0:dd/MM/yyyy}",rpt.Fields["AppointmentResourceLink.Appointment.Patient.DateDied"].Value); }

catch(System.Exception e)

{ System.String.Format("{0:dd/MM/yyyy}",rpt.Fields["AppointmentResourceLink.Appointment.Patient.DateDied"].Value);
}

return "";

Aus Gamer
  • 1
  • 1