Web Form Redirect to Dynamic URL

Can I create a webform page with a redirect to a dynamic url.

I have a case like this:

  1. when I submit on the webform with DocType TicketTripwe, I set the script server in the doctype, which is used to create an automatic reference.
def before_insert(Document):
        strRandom = TicketTripwe.random_string(5)
        current_date = datetime.now().strftime("%d%m%y")
        reference_field = "TP" + current_date + strRandom
        if Document.reference is None or not Document.reference:
            Document.reference = reference_field
            Document.barcode = reference_field
  1. WebForm will redirect to the page /detail-ticket.html?q={reference}

can anyone help me?