How do I apply a form template to a form on load?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2023 11:56 PM
Hi all,
I have a saved template called Story Template.
I want that template to be applied every time the story form loads. How do I script it?
I tried UI Policy script.
Description is empty AND
Acceptance Criteria is empty
g_form.applyTemplate('Story Template');
//Also tried the below methods.
// g_form.setActiveTemplate('Story Template');
// g_form.setTemplate('Story Template')
The last two were suggested by ChatGPT 😄
Regards,
Anish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2023 12:43 AM - edited 03-17-2023 12:44 AM
I think g_form is not required just use the applyTemplate('<pass template sys_id>'),
You can refer to the following articles for more - https://servicenowguru.com/system-definition/advanced-templates/
https://www.servicenow.com/community/itsm-articles/script-to-apply-template-to-create-pre-defined-su...
If I could help you with my response you can mark it as helpful and correct as it benefits future viewers
Thanks,
Sai Kumar B
Community Rising Star 2023 & 2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2023 12:52 AM
Tried, but does not work buddy.
Thanks,
Anish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2023 01:14 AM
Do one thing
1.) Use onLoad() client script call client callable script include using GlideAjax()
2.) In the script include use server-side methods to apply the template on the target record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2023 01:25 AM
Hi @Anish Reghu Please try onLoad client script.
Please mark correct or helpful if it works.
Thanks,
Vallabh