Dynamically change fPort in encodeDownlink?

Hi all,
Is it possible to dynamically change the downlink fPort in encodeDownlink based on some logic?

function encodeDownlink(input) {
  ...
 // Dynamically change downlink fPort based on some logic
 var fPort = 9;

  // Return the downlink message in the format required by TTN
  return {
    bytes: payload,  // Byte array to send
    fPort: fPort,    // Dynamically set fPort
    warnings: [],
    errors: []
  };
}

Thanks a lot and have a nice day.

The warnings and errors are not needed and can be ignored.