SwapnilBankar - thanks for quickly trying it out.
Just to narrow down a little bit, I need your help.
1) Please let me know the logic app extension version that you are using in VS Code
2) Please try the scenario with "If" function (instead of If Else). Something like "if (isNull(surname)) Surname = $null" kind of a map. Make sure to use the construct that shows $null in the code view. Let me know if this generates the right transformation for you. This will help us narrowing down the issue you are having.
3) Help us understand what the unique ID requirement is? Is the incoming message XML? Do you want to generate unique ID for each node? Do the IDs need to be unique for a session or for the eternity?
4) Here are a few links on custom extensibility
Data Mapper for Azure Logic Apps (Standard) reaches General Availability - Microsoft Community Hub
Create maps for data transformation - Azure Logic Apps | Microsoft Learn (Checkout "Create a custom function" section)
5) If need be, we can set-up some time to talk. (I have sent you a DM here, please check)