Created
October 11, 2016 09:46
-
-
Save Sarapulov/9495729b80e001abcb75f51c6536a354 to your computer and use it in GitHub Desktop.
Quick and dirty way to read URL parameters and set given ticket fields Expected URL example https://sarapulov.zendesk.com/hc/en-us/requests/new?ticket_form_id=72316&country=bhutan&age=21 CODE CONTAIN BUGS!
This file contains hidden or 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
/* | |
Quick and dirty way to read URL parameters and set given ticket fields | |
Expected URL example https://sarapulov.zendesk.com/hc/en-us/requests/new?ticket_form_id=72316&country=bhutan&age=21 | |
CODE CONTAIN BUGS! | |
*/ | |
if ( window.location.search.match("ticket_form_id") ) { | |
function getUrlParameter(param) { | |
if (!param) return ''; | |
var href = window.location.href; | |
if (param === 'locale') return href.split('/hc/')[1].split('/')[0]; | |
else return href.split(param+'=')[1].split('&')[0]; | |
} | |
function setField(field_id,value){ | |
var $elem = $('#'+field_id); | |
$elem.val(value); | |
$elem.siblings('.nesty-input').text(value); | |
console.log(field_id + " :: " + value); | |
} | |
var fields = [['request_custom_fields_23545273',getUrlParameter('country')],['request_custom_fields_24346859',getUrlParameter('age')],['request_description',getUrlParameter('locale')]]; | |
fields.forEach(function(arr){setField(arr[0],arr[1])}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment