- 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
Wednesday
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
Wednesday
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
Wednesday
Hi @Dr Atul G- LNG,
I am aware that when you apply a template the fields will mapped, that's OOB functionality .
But here my requirement is to auto populate the field values without applying (i.e, without clicking on the template).
I have attached the business rule like how I was trying to auto populate the fields.
Whatever the details I have given in template need to auto populate to the problem_task field while a task is creating, not by clicking on template to apply.
Hope the information is attained.
Any suggestions on this requirement will be appriciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Wednesday
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
Wednesday
Hi @YamunaRaniK
Not a possible or valid case, mate. How will the system know which values to populate without the template? The values would differ each time. If you’re using a template, let’s fix the field values and use them accordingly. Don’t create technical debt for the system.
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]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Wednesday
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.
