Last active
September 15, 2017 16:01
-
-
Save benyanke/994ce01b938fd2d1eb9ec1a0ecb79b35 to your computer and use it in GitHub Desktop.
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
// SpiceWorks ticket autofill | |
// Autofills the ticket based on get variables in the URL of the ticket. | |
// This file is at: https://gist.github.com/benyanke/994ce01b938fd2d1eb9ec1a0ecb79b35 | |
// | |
// Also usable on sites at either of the following URLs. | |
// Original gist: | |
// https://gist.githubusercontent.com/benyanke/994ce01b938fd2d1eb9ec1a0ecb79b35/ | |
// | |
// Raw gist content: | |
// https://gist.githubusercontent.com/benyanke/994ce01b938fd2d1eb9ec1a0ecb79b35/raw/spiceworksTicketAutofill.js | |
// | |
// Minified version for using on sites: | |
// https://gistcdn.githack.com/benyanke/994ce01b938fd2d1eb9ec1a0ecb79b35/raw/spiceworksTicketAutofill.js | |
// Created by Ben Yanke <byanke@pcnametag.com> | |
// September 13, 2017 | |
function autofillFieldsFromUrl() { | |
// Set up initial var for containing values | |
var getvars = {}; | |
if(document.location.toString().indexOf('?') !== -1) { | |
// Parse through URL to get values | |
var query = document.location | |
.toString() | |
// get the query string | |
.replace(/^.*?\?/, '') | |
// and remove any existing hash string (thanks, @vrijdenker) | |
.replace(/#.*$/, '') | |
.split('&'); | |
// Store the values in getvars | |
for(var i=0, l=query.length; i<l; i++) { | |
var aux = decodeURIComponent(query[i]).split('='); | |
getvars[aux[0]] = aux[1]; | |
} | |
console.log("Setting ticket values based on get autofill vars"); | |
// Set form values from data in getvars | |
// Customize these to specify which IDs are autofilled by which get variables | |
if ('summary' in getvars) { | |
console.log("Setting summary to : '" + getvars['summary'] + "'"); | |
document.forms['edit_custom_ticket_form_1']['custom_ticket_form_field_2'].value = getvars['summary']; | |
} | |
if ('category' in getvars) { | |
console.log("Setting category to : '" + getvars['category'] + "'"); | |
document.forms['edit_custom_ticket_form_1']['custom_ticket_form_field_13'].value = getvars['category']; | |
} | |
if ('notes' in getvars) { | |
console.log("Setting notes to : '" + getvars['notes'] + "'"); | |
document.forms['edit_custom_ticket_form_1']['custom_ticket_form_field_8'].value = getvars['notes']; | |
} | |
if ('duedate' in getvars) { | |
console.log("Setting due date to : '" + getvars['duedate'] + "'"); | |
document.forms['edit_custom_ticket_form_1']['custom_ticket_form_field_7_custom_ticket_form_field_7_date'].value = getvars['duedate']; | |
} | |
} | |
} | |
// Run the autofill script | |
autofillFieldsFromUrl(); |
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
function autofillFieldsFromUrl(){var a={};if(-1!==document.location.toString().indexOf("?")){for(var c=document.location.toString().replace(/^.*?\?/,"").replace(/#.*$/,"").split("&"),b=0,e=c.length;b<e;b++){var d=decodeURIComponent(c[b]).split("=");a[d[0]]=d[1]}console.log("Setting ticket values based on get autofill vars");"summary"in a&&(console.log("Setting summary to : '"+a.summary+"'"),document.forms.edit_custom_ticket_form_1.custom_ticket_form_field_2.value=a.summary);"category"in a&&(console.log("Setting category to : '"+ | |
a.category+"'"),document.forms.edit_custom_ticket_form_1.custom_ticket_form_field_13.value=a.category);"notes"in a&&(console.log("Setting notes to : '"+a.notes+"'"),document.forms.edit_custom_ticket_form_1.custom_ticket_form_field_8.value=a.notes);"duedate"in a&&(console.log("Setting due date to : '"+a.duedate+"'"),document.forms.edit_custom_ticket_form_1.custom_ticket_form_field_7_custom_ticket_form_field_7_date.value=a.duedate)}}autofillFieldsFromUrl(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment