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

Anish Reghu
Kilo Sage
Kilo Sage

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

5 REPLIES 5

Sai Kumar B
Mega Sage
Mega Sage

@Anish Reghu 

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

 

 

Tried, but does not work buddy.

 

Thanks,

Anish

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

 

Vallabh Baradk2
Giga Guru

Hi @Anish Reghu  Please try onLoad client script.

 

Please mark correct or helpful if it works.

 

Thanks,

Vallabh