Last active
February 28, 2024 11:06
-
-
Save stresslimit/1ab47692f2421855fa2e to your computer and use it in GitHub Desktop.
Pre-populate Zendesk new ticket fields via query params
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(function($) { | |
if ( !$('#new_request') ) return | |
var query = window.location.search.substring(1); | |
var vars = query.split("&"); | |
var match, fieldID; | |
for (var i=0; i<vars.length; i++) { | |
var pair = vars[i].split("="); | |
match = pair[0].match(/^request_fields\[([a-z_\d]+)\]$/) | |
if (match) { | |
fieldID = match[1]; | |
$('#request_' + fieldID).val( decodeURIComponent(pair[1]) ); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// build your data | |
var field_data = { | |
"anonymous_requester_email": "", // email | |
"subject": "", // subject | |
"description": "that shit cray", // description | |
"custom_fields_23823917": "", // your name | |
"custom_fields_23823947": "bit_module_wire__orange___cloudbit" // which module [cloudBit] | |
} | |
// parse it out for our url format | |
var q = [] | |
for ( var k in field_data ) { | |
if (field_data.hasOwnProperty(k)) { | |
q.push('request_fields[' + k + ']=' + encodeURIComponent(field_data[k]) ) | |
} | |
} | |
// wrap it up | |
var zd_url = 'https://support.littlebits.cc/hc/en-us/requests/new?ticket_form_id=28986&' | |
var redirect_url = zd_url + q.join('&') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment