How to Prefill Subject and Description Based on Category in BoldDesk
You can enhance the ticket creation process in BoldDesk by automatically pre-filling the Subject and Description fields based on the selected category. This customization pre-fills the Subject and Description fields on the BoldDesk Customer Portal ticket creation form based on the selected Category. The behaviour is implemented using Custom JS and runs in the end-user browser during ticket submission.
Custom JS code
Use the following script to automatically populate the Subject and Description fields when a specific category is selected:
function initCategory() {
var categoryEl = document.querySelector('.categoryId .e-control');
if (!categoryEl || !categoryEl.ej2_instances) {
return setTimeout(initCategory, 500);
}
var category = categoryEl.ej2_instances[0];
var submitBtn = document.querySelector('.create-ticket-update-button button');
function updateFields() {
var subject = document.querySelector('#subject_wrapper input')?.ej2_instances?.[0];
var rte = document.querySelector('.e-richtexteditor')?.ej2_instances?.[0];
if (!subject || !rte) return;
if (category.value === 85) {
var text = "<p>Employee request: " + category.text + "</p>";
subject.value = category.text;
subject.dataBind();
rte.value = text;
rte.dataBind();
} else {
subject.value = "";
subject.dataBind();
rte.value = "";
rte.dataBind();
}
}
var originalChange = category.change;
category.change = function () {
originalChange && originalChange.apply(this, arguments);
setTimeout(updateFields, 300);
};
submitBtn?.addEventListener('click', function (e) {
if (category.value !== 85) return;
e.preventDefault();
updateFields();
setTimeout(() => submitBtn.click(), 250);
});
}
initCategory();
Pasting the Custom JS Code
To implement this functionality, copy and paste the script into the Custom JS section of your BoldDesk Customer Portal settings.
Explore How to Customize the BoldDesk Customer Portal.
Before Customization
After Customization
How It Works
- Detects the selected category in the ticket form
- Automatically fills:
- Subject with the category name
- Description with a formatted message
- Clears the fields when a different category is selected
- Ensures values are applied before ticket submission
Key Customization Options
You can also customize the following;
Change the Category Condition
Update this comparison everywhere it appears:
if (category.value === 85) { ... }
Change the Description Template
Update the HTML string:
var text = "<p>Your custom message here</p>";
Support Multiple Categories
Add additional conditions using else if blocks:
if (category.value === 85) {
// template A
} else if (category.value === 763) {
// template B
} else {
// clear fields
}
- The script depends on EJ2 control instances (
ej2_instances). If the page loads slowly or markup changes, selectors may fail - The clearing logic in the
elsebranch will remove user-entered Subject/Description if the category changes away from the configured category ID. - The script runs only on pages where the selectors exist (ticket creation UI in the Customer Portal).
Troubleshooting
Subject/Description does not populate
- Confirm the script is saved in Customer Portal → Custom JS (not agent portal).
- Confirm the category control is found by the selector:
.categoryId .e-control
- Confirm EJ2 instances exist:
categoryEl.ej2_instances#subject_wrapper inputhasej2_instances.e-richtexteditorhasej2_instances
Wrong category triggers the prefill
- Verify the category ID value used in the script matches the intended category ID in your portal:
- Replace
85with the correct ID (example mentioned:763).
- Replace
Script runs inconsistently
- Check browser console for JavaScript errors.
- Confirm the page has fully rendered before interactions; the script retries initialization every 500 ms until the category EJ2 instance exists.
Fields clear unexpectedly
- Review the
elsebranch that clears both fields when the category is not the target category ID. - If you want to keep user input for non-target categories, remove the clearing logic.
Frequently Asked Questions
-
Can the prefill support multiple categories with different templates?
Yes. Addelse if (category.value === <ID>)branches and set different Subject/Description values per category. -
Can users edit the prefilled Subject and Description?
Yes. The script writes initial values, and users can modify both fields before submission. -
Does this change any existing tickets?
No. The script only affects the Customer Portal ticket creation form at submission time. -
Can the Description include formatting (bold, lists, links)?
Yes. The description string is HTML (for example,<p>...</p>), which is assigned to the rich text editor value. -
Why does the script use
setTimeoutwhen updating fields?
The delay helps ensure the EJ2 control state is available and stable before writing values and callingdataBind(). -
What happens if the selectors change in a portal theme update?
The script may stop working until the CSS selectors (for category, subject, or editor) are updated to match the new markup. -
Does this require any BoldDesk workflow automation rules?
No. This behavior is client-side only and does not rely on server-side automations.