How can I pull the ID # from a URL into a hidden field on a HS form

Hello!

I am quite new to HubSpot and I need help with capturing an ID # within the URL of a HS form. Specifically, how can I pull the ID # from a URL into a hidden field on a form?

I read that I need to implement a custom script that extracts the ID # from the URL and populates the hidden field with this value.

But I do not know how to write a custom script to capture this ID from the URL. I would imagine, I would need to write some JS to do this.

To further explain my request I have an example URL below.
https://www.columbiasouthern.edu/info-form?utm_source=MilitaryEdRep&utm_medium=Other&repcode=230&utm_campaign=General&leadsourceid=1844

I want/need to capture that leadsourceid # 1844 at the end of the URL into a hidden field.

Can anyone assist me on how to capture this number? Thank you in advance!

@PMc8 - luckily this is quite a simple thing to capture.

If you can make the query parameter name (as in URL?parametername=myvalue) match the internal name of the form field property, then the hidden field value on the form will be poulated.

See; Auto-populate form fields with a query string

If you can’t make the parameter name match the internal property name, then it’s also possible to do a bit of parsing on the ‘last page seen’ URL value to extract an arbitrary query property value (this may require some cusom code work depending on complexity) using a workflow and store the captured value in your chosen property.

Hope that helps!

Steve

@SteveHTMThank you for your quick response! So if I follow you correctly, then I need to make a hidden field property with the same name as the URL parameter name value that I want to capture.

The query parameter name that I want to capture is General&leadsourceid.

If I give the hidden field property the same name General&leadsourceid then it should capture the id number?

Yes. Well apart from not using a ‘&’ character in the proposed name, I think it could be that simple. Good luck!

@SteveHTM You mentioned the exact issue I am facing- the URL parameter has an uppercase “I” so the internal Hubspot value is not matching. Do you have any example codes I could reference for capturing the 15-digit value after “referrerId”? Or is it something like Excel where you parse "=right(“field”, 15)?

@GAlvarez07 - fr my issues with this, I used a Custom code workflow step to be able to invoke a couple of line of Python code that translate the URL string to one that can be stored in the HubSpot property. As mentioned I used that code on the ‘last page seen’ Contact property after the submit action - so the action is not as immediate or as integrated as if the query string contained the correct internal property name as documented.

Steve