- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2025 03:34 AM
Hi All,
I have created some templates for a custom field.
In the custom field, there is a reference field (Template)referencing to the sys_template table (I have added the filter to show only templates related to the table).
On change of Template field, values of that template should be copied to the string fields of the table.
Please help me.
Thanks,
Sam
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2025 05:47 AM
this worked for me
Template:
onChange client script: on that template field
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var values = g_form.getReference('u_template').template; // give here the field name
var fieldValuePairs = values.split('^');
// Loop through each pair and set the value on the form
fieldValuePairs.forEach(function(pair) {
var [field, value] = pair.split('=');
if (field && value) {
g_form.setValue(field, value);
}
});
//Type appropriate comment here, and begin script below
}
Output:
Before: when template is not selected
After selecting template fields populated
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2025 03:37 AM
Hi @Samiksha2
No, it is not possible unless you have that field in the template and under the table. You can't copy the template file directly to the table.
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
03-26-2025 04:19 AM
you created template for your custom table.
Now on your table you have a field which refers to sys_template and want to bring the value
Use this in onChange with getReference() callback
1) get the values as encoded query
2) split and then set each field value
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2025 04:23 AM
when user opens form, he/she can apply template from bottom.
why not use that to set the values?
when user clicks on that template, the field values are set
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2025 05:25 AM
Hi @Ankur Bawiskar,
Client wants to be that template should be in the drop down.