Count how many times a template is used?

howard8
Tera Contributor

I have a requirement to keep track of how many times each template is applied to a form, so we can report on templates that are not getting used that much.

Does anyone know where the code is that applies the template, so I can add some counter increment code?   I am not seeing it all.

Thanks.

3 REPLIES 3

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Thanks but it doesn't address the question of how to intercept the standard method of applying templates, in order to run additional code. It talk's about how you can apply them programmatically.


Hi Howard,



Thanks to @solutioner now.



Please do below steps to achieve your requirements:



1) Create Count(u_count) integer field on sys_template table


2) Update exiting UI Macro "template_context" to update the count of the template.


Replace below line of code.


<script>


mApplyTemplates.addHref("$[jvar_template.getLabel()]", "applyTemplate('$[jvar_template.getValue()]')");


</script>


With below code:


    <script>


function updateCount(id){


var gr = new GlideRecord('sys_template');


gr.get(id);


gr.u_count++;


gr.update();


applyTemplate(id);


}


mApplyTemplates.addHref("$[jvar_template.getLabel()]", "updateCount('$[jvar_template.getValue()]')");


</script>




Re: How to Count Number of times the Template is used ?



Thanks


Srini