- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tuesday
Hi Everyone,
I have a requirement to Auto populate Short description and Description fields of a Problem Task whose type is Risk Accepted (Like Root Cause Analysis) from a pre-defined template.
I tried using Business and Client script + script include but nothing is working as expected.
I tried to query the fields of my template which is present in sys_template table in background script but nothing is coming as result.
Does anyone know the behavior of sys_template table, can anyone help me on this requirement.
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
I don't think it's a valid requirement to use script to set the fields when you can easily do this with templates.
But if you still require then you need to grab the encoded string from template, do string manipulation and then grab the short description and description and then set it
Something like this
var gr = new GlideRecord("sys_template");
gr.addQuery("name", "value");
gr.query();
if (gr.next()) {
var input = gr.template.toString();
var parts = input.split('^');
var shortDescription = '';
var description = '';
for (var i = 0; i < parts.length; i++) {
var keyValue = parts[i].split('=');
if (keyValue[0] === 'short_description') {
shortDescription = keyValue[1] || '';
}
if (keyValue[0] === 'description') {
description = keyValue[1] || '';
}
}
current.short_description = shortDescription;
current.description = description;
}
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
If you want to auto populate fields when form loads or any specific field changes, it can easily be achieved by using client script. According to your condition, set value of the description and short description fields on the form. Why are you using template?
If you need help in client script, let me know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tuesday
so when template is applied you want to Auto populate short description and Description?
why not set those in template itself?
what's your business requirement?
share screenshots etc
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @Ankur Bawiskar ,
Thanks for the response.
I am attaching the template I have created and the business rule which is written on problem_task table before insert. The background script that I tried to pull all the names of the sys_template returning some other table.
The Short description and description need to auto populate when a problem task is getting created.
Any suggestions on it will be very helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
you already have short description and description in template.
when you apply template those 2 fields are not getting auto-populated?
how are you applying the template? share screenshots.
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @YamunaRaniK
Template means to populate the preloaded values into the actual fields. If the template already has values, they get automatically mapped and copied to the corresponding fields when you apply the template. There’s no difference or additional logic needed around it — it’s all out of the box (OOTB).
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************