Create "Name" of record based on Multiple Text Property Values

SOLVE
aljones
Participant

I want to autocreate the "Ticket Name" field based on the selection of the subsequent properties. Ideally I would like it to look something like this:

 

First Name + Last Name +" - " + Lead Source + date

John Smith - CSG Webinar 9/5/2021

 

It looks like you can only create calculations based on number values

and it doesn't look like I can copy and join multiple single line property values from different objects into one target property field.

 

I couldn't find a solution in any of the other discussions - so any advice would be welcome.

0 Upvotes
1 Accepted solution

Accepted Solutions
piersg
Solution
Key Advisor

There's this page, specifically the example of running a script when a form submits. If you have a hidden field in your form for the ticket name, you could do something like this on submit (I've put in guesses as to what the field names would be):

<!--[if lte IE 8]>
    <script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2-legacy.js"></script>
    <![endif]-->
    <script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"></script>
    <script>
      hbspt.forms.create({
      portalId: "[PORTAL ID]",
      formId: "[FORM ID]",
        onFormSubmit: function(form){
            var firstName = form.querySelector('input[name="firstname"]').value;
            var lastName = form.querySelector('input[name="lastname"]').value;
            var leadSource = form.querySelector('input[name="lead_source"]').value;
            var date = new Date();
            date = date.toLocaleDateString('en-GB'); // will give you date in dd/mm/yyyy format
            form.querySelector('input[name="ticket_name"]').value = `${firstName} ${lastName} - ${leadSource} ${date}`;
        }
      });
    </script>

 

There's one downside to this method. If you're redirecting to another page, e.g. a thank you page, that redirection might happen before the above code executes and the form is sent. It would be fine with a thank you message.

 

Another method, which will make sure data is changed and sent before any redirection happens if you're using a redirect, is this:

{% form
form_to_use="{{ module.form.form_id }}"
response_response_type="{{ module.form.response_type }}"
response_message="{{ module.form.message }}"
%}
{% if module.form.redirect_id %}
<script>
  window.addEventListener('message', event => {
    if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmit') {
    	let firstName = event.data.data.find(o => o.name === 'firstname');
    	let lastName = event.data.data.find(o => o.name === 'lastname');
    	let leadSource = event.data.data.find(o => o.name === 'lead_source');
		var date = new Date();
        date = date.toLocaleDateString('en-GB'); // will give you date in dd/mm/yyyy format
        form.querySelector('input[name="ticket_name"]').value = `${firstName.value} ${lastName.value} - ${leadSource.value} ${date}`;
      
    }
    if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmitted') {
        {% set redirect = content_by_id(module.form.redirect_id) %}
        window.location = '{{redirect.absolute_url}}'
    }
  });
</script>
{% endif %}

 

View solution in original post

6 Replies 6
dennisedson
Community Manager

@aljones , how are you creating the records?  Via a form?

@piersg might have some thoughts.

Thanks,

Dennis




Check out our Community Developer Blog
where we feature our Community driven developer podcast and how to content
0 Upvotes
aljones
Participant

@dennisedson  - yes  - it will be via form.

0 Upvotes
piersg
Key Advisor

How is the ticket being submitted? If it's a form on a website page you could do this with some JS at the point of submission.

0 Upvotes
aljones
Participant

@piersg  thank you - can you direct me to any documentation on this?

0 Upvotes
piersg
Solution
Key Advisor

There's this page, specifically the example of running a script when a form submits. If you have a hidden field in your form for the ticket name, you could do something like this on submit (I've put in guesses as to what the field names would be):

<!--[if lte IE 8]>
    <script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2-legacy.js"></script>
    <![endif]-->
    <script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"></script>
    <script>
      hbspt.forms.create({
      portalId: "[PORTAL ID]",
      formId: "[FORM ID]",
        onFormSubmit: function(form){
            var firstName = form.querySelector('input[name="firstname"]').value;
            var lastName = form.querySelector('input[name="lastname"]').value;
            var leadSource = form.querySelector('input[name="lead_source"]').value;
            var date = new Date();
            date = date.toLocaleDateString('en-GB'); // will give you date in dd/mm/yyyy format
            form.querySelector('input[name="ticket_name"]').value = `${firstName} ${lastName} - ${leadSource} ${date}`;
        }
      });
    </script>

 

There's one downside to this method. If you're redirecting to another page, e.g. a thank you page, that redirection might happen before the above code executes and the form is sent. It would be fine with a thank you message.

 

Another method, which will make sure data is changed and sent before any redirection happens if you're using a redirect, is this:

{% form
form_to_use="{{ module.form.form_id }}"
response_response_type="{{ module.form.response_type }}"
response_message="{{ module.form.message }}"
%}
{% if module.form.redirect_id %}
<script>
  window.addEventListener('message', event => {
    if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmit') {
    	let firstName = event.data.data.find(o => o.name === 'firstname');
    	let lastName = event.data.data.find(o => o.name === 'lastname');
    	let leadSource = event.data.data.find(o => o.name === 'lead_source');
		var date = new Date();
        date = date.toLocaleDateString('en-GB'); // will give you date in dd/mm/yyyy format
        form.querySelector('input[name="ticket_name"]').value = `${firstName.value} ${lastName.value} - ${leadSource.value} ${date}`;
      
    }
    if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmitted') {
        {% set redirect = content_by_id(module.form.redirect_id) %}
        window.location = '{{redirect.absolute_url}}'
    }
  });
</script>
{% endif %}

 

View solution in original post

aljones
Participant

thanks @piersg  - hopefully this works for us!

0 Upvotes