@Sajith
Instead of the process you are attempting, consider the following:
For updating an existing record or creating a new record:
Patch(dataSource,
Coalesce(LookUp(dataSource, ID=ThisItem.ID), Defaults(dataSource)),
{ ... record info...}
)
The above will lookup the record and if it exists, it will be patched, if not, then it will create a new record.
Also using the collect function instead:
Collect(dataSource,
{ID: ThisItem.ID,
...the rest of the record...}
)
The above will create a new record if ID is blank, otherwise, it will update the record with the ID provided.
I hope this is helpful for you.