Solved

Pre-populated ticket fields

  • 24 November 2022
  • 6 replies
  • 116 views

Userlevel 6
Badge +11

Hello, 

I’m looking for a way to populate fields/drop down/check boxes using a URL 

So I can have card on the end user portal with like this url 

myitsm.freshservice.com/support/home?category=HR?employeetype=Consulting?active=True

“employeetyp” is a drop down field 
“active” is a checkbox 

 

Has anyone manage to get something to work ? 

 

TIA

Daniel

icon

Best answer by Rutger Bockholts 25 November 2022, 16:06

View original

6 replies

Userlevel 3
Badge +2

Hi Daniel,

 

The different parameters in the url have to be separated with the “&” character instead of the “?”. Format wise, below url should do the trick:

https://example.freshservice.com/support/tickets/new?category=HR&employeetype=Consulting&active=true

 

The script can be added via Helpdesk Rebranding - Customize Custom Portal - Layout & Pages - Portal Pages - New Ticket.

Field ID's (#****) in the script have to be adjusted to your own environment. For the Dropdown menus on the portal, you can find the field ID's in the <Select section of the page source. If you need help with this, I can provide some page source examples where to find them.

 

<script>
jQuery(document).on('PageUpdate', function() {

// (un)select checkbox
var active_input = getParameterByName('active');
console.log('active_input: ' + active_input);

if (active_input == 'True' || active_input == 'true') {
var checkBox = document.getElementById('27000156639');
checkBox.checked = false;
checkBox.onchange = function () {
document.getElementById("27000156639").checked = true;
};
checkBox.onchange();
} else {
var checkBox = document.getElementById('27000156639');
checkBox.checked = false;
checkBox.onchange = function () {
document.getElementById("27000156639").checked = false;
};
checkBox.onchange();
}

// Employeetype dropdown selection
var employeetype_input = getParameterByName('employeetype');
console.log('employeetype_input: ' + employeetype_input);
$("#27000156640").val(employeetype_input).show().trigger("change");

// Category dropdown selection
var category_input = getParameterByName('category');
console.log('category_input: ' + category_input);
$("#27000073325").val(category_input).show().trigger("change");

});
</script>

 

 

 

 

Hope this helps. I'm looking forward for your result.

 

Kind regards,

 

Rutger Bockholts

Freshworks

Userlevel 6
Badge +11

@Rutger Bockholts 

Thanks , you are right it should be &, something was wrong when I wrote the URL but couldn’t put my finger on what is was. 

 

Did some smal Tests and it worked great, going to post some more when I have a full setup. 

 

//Daniel 

Badge +4

Could you also populate a dependet field?

And how do you handle field with spaces in them?

 

Userlevel 3
Badge +2

Could you also populate a dependet field?

And how do you handle field with spaces in them?

 

Hi Anders,

 

A dependent field is possible as well. In below script lines I take the Category field as an example.

Be aware that the main Category value behind the # is a numbered ID, however the sub-category and item-category are both named ID's. In your case, you only have to replace the category ID and the values into a static value or use a variable as showed in my previous post.

    // Category field:
    $("#27000073325").val('Hardware').show().trigger("change");


    // Sub Category:
    $("#sub_category").val('Computer').show().trigger("change");

 

    // Item Category:
    $("#item_category").val('Tablet').show().trigger("change");  

 

For your second question, I'm not sure what you mean. If you want to populate a value that contain spaces, you can just add them as-is as a value:

$("#item_category").val('Notebook and drawing tablet').show().trigger("change"); 

If you need something else, please let me know.

 

Kind regards,

 

Rutger Bockholts

Freshworks

Badge +4

Thanks for the fast reply.

How would the above example end up in an URL?

I wasn´t that clear in my question but I am looking for direct URL to use.

Userlevel 3
Badge +2

Hi Anders,

 

With the following url you can pre populate the values in the Category fields:

https://example.freshservice.com/support/tickets/new?category=Hardware&sub_category=Computer&item_category=Notebook%20and%20drawing%20tablet

As you can see, the spaces for the item category field are notes with “%20”, which is the html code for a space. The script below will do a check in the item category part for this space and replace the “%20” code with an actual space.

When someone is loading the incident form without above url, you don't want additional errors in the console, so I've added an check if the char “&” exist in the url. If not, the rest of the script will be skipped.

 

<script>
jQuery(document).on('PageUpdate', function() {
var current_url = window.location.href.toString();
if(current_url.includes("&")) {

// Category field:
var url_category = getParameterByName('category');
console.log('url_category: ' + url_category);
$("#27000073325").val(url_category).show().trigger("change");

// Sub Category:
var url_subcategory = getParameterByName('sub_category');
console.log('url sub category: ' + url_subcategory);
$("#sub_category").val(url_subcategory).show().trigger("change");

// Item Category
var url_itemcategory = getParameterByName('item_category');
if (url_itemcategory.includes("%20")) {
url_itemcategory = url_itemcategory.replace("%20", " ");
}
console.log('url item category: ' + url_itemcategory);
$("#item_category").val(url_itemcategory).show().trigger("change");
}
});
</script>

 

Kind regards,

 

Rutger Bockholts

Freshworks

Reply