Error as Object reference

Hi All,

I am getting the following error If: Object reference not set to an instance of an object. Attached my excel file and workflow for reference . Can anyone help me in knowing why the error is coming

PDF_Automation (2).zip (56.6 KB)
pdf.xlsx (9.4 KB)
SalesForce_OutputFields.xlsx (9.6 KB)

if((ColumnDisc(column.ColumnName)=“st_date"or ColumnDisc(column.ColumnName)=“end_date”),DateTime.ParseExact(CurrentRow.ByField(ColumnDisc(column.ColumnName)).ToString.Trim,{“M/d/yyyy”,“M-d-yyyy”,“MM/dd/yyyy”,“MM-dd-yyyy”},System.Globalization.CultureInfo.InvariantCulture).ToString(“ddMMyyyy”),CurrentRow.ByField(ColumnDisc(column.ColumnName)).ToString.replace(“USD”,”“).Trim) = if((column.ColumnName=“Start Date” or column.ColumnName=“End Date”),DateTime.Parse(dt_PDF.Rows(CurrentIndex-1).Item(column.ColumnName).ToString.Trim).ToString(“ddMMyyyy”),dt_PDF.Rows(CurrentIndex-1).Item(column.ColumnName).ToString.Replace(”$“,”").Trim)

The error is in the condition of the If statement. That’s why the initial error says If:

The “object reference not set to an instance of an object” error means you’re trying to use a variable or other expression that doesn’t exist. For example, ColumnDisc(“hello”) but there’s no key named “hello” in ColumnDisc.

You have a very complicated statement there. Are you sure that’s all necessary? I would recommend doing conversions etc ahead of time to simplify that statement. Don’t do it all in one line - this makes debugging a nightmare.

Thanks Paul. If I want to convert any date format to {“M/d/yyyy”,“M-d-yyyy”,“MM/dd/yyyy”,“MM-dd-yyyy”},System.Globalization.CultureInfo.InvariantCulture).ToString(“ddMMyyyy”) how to do the conversions before hand. shall i assign a variable and do the conversions and then replace it in the if condition? Can you help in this?

Create a string variable and use an Assign activity to assign the converted value to the variable. Then in the If condition replace the conversion expression with the variable.