# Alternative approach using ISOMsg.clone/1 + filtering defp clone_supported_fields_alternative(%ISOMsg{} = message) do supported_fields = [2, 3, 4, 11, 12, 13, 14, 22, 23, 24, 25, 35, 37, 38, 39, 41, 42, 49, 52, 55, 62, 63] # Step 1: Clone the entire message (preserves ISOComponent structure) cloned_message = ISOMsg.clone(message) # Step 2: Remove unsupported fields filtered_message = cloned_message.fields |> Map.keys() |> Enum.reduce(cloned_message, fn field_num, acc_msg -> if field_num in supported_fields do acc_msg # Keep supported fields else ISOMsg.unset(acc_msg, field_num) # Remove unsupported fields end end) {:ok, filtered_message} end