How to Count Number of times the Template is used ?

Gaurav Kumar15
Giga Guru

Hi All,

 

We want to track the number of times a specific template is used. We would like to see which templates are used more frequently.

for e.g :- If i have created a template by the name "P2 Incident" and it has been used on the 5 incidents, then i want to capture that number "5" in some field, as it has been used 5 times.

 

Could anyone please suggest a way for implementing the solution to this requirement ?

 

TIA

8 REPLIES 8

amadosierra
Kilo Guru

As far as I know, OOB there is no trace of what template was used to create a record.


One way to do it would be adding a reference field to the Task table (it doesn't have to be visible) where you can set the template name used from the template itself.



/Amado


solutioningnow
Giga Guru

Hello,




To implement the count you need to do below configurations




1) Create new field on sys_template table


2) Update exiting UI Macro "template_context" to update the count of the template. In this macro, you basically need to update below line of code:


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




You can create one function which will increment the count and apply the template



Please mark answer as correct/helpful, if it was really helpful



Regards,


Solutioner


Logo.png


Enhance Knowledge NOW@ www.solutioningnow.com


http://www.solutioningnow.com/


Hi solutioner now,



Thanks for the reply.


Could you please elaborate step no. 2   , on where to create a function and how we can have to insert that function in the line of the code you mentioed ?



TIA


Hi Gaurav,



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>




Please mark answer as correct, if it was really helpful



Regards,


Solutioner


Logo.png


Enhance Knowledge NOW@ www.solutioningnow.com


http://www.solutioningnow.com/