How to domain separate the templates?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2025 06:00 AM
Is there a way to separate templates by domain? I know I can limit visibility by groups, but I was wondering if it’s possible to separate them by domain as well.
In the snippet from the agent workspace below, it shows that the user can see all the templates, which are specific to their group. I want the templates to be visible based on the record or the user’s domain. How can I achieve this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2025 09:36 AM
@Chaitanya ILCR, Thanks for suggesting. Can you guide me with the script?
Tried the below On Before query Business rule:
(function executeRule(current, previous /*null when async*/ ) {
var incidentDomain = current.sys_domain;
gs.log('incident domain is: ' +incidentDomain,'Swapnil');
// Add query to restrict templates to the same domain as the incident
var templateQuery = new GlideRecord('sys_template');
templateQuery.addQuery('sys_domain', incidentDomain);
templateQuery.addEncodedQuery("table=incident");
templateQuery.query();
gs.log('row count' +templateQuery.getRowCount);
// Modify the query to only include matching template IDs
var templateIds = [];
while (templateQuery.next()) {
var allTemplates = templateIds.push(templateQuery.sys_id.toString());
gs.log('All templates are: ' +allTemplates,'Swapnil');
}
if (templateIds.length > 0) {
gs.log('Enter if');
current.addQuery('sys_id', 'IN', templateIds);
} else {
gs.log('Enter else');
// current.addQuery('sys_id', '=', 'nonexistent_id');
}
})(current, previous);
Gets the domain sys id, but it never finds the template on the sys_template table, returns 0 and goes to the else loop. Am I missing anything here?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2025 10:02 AM
Hi @SwapnilC ,
based on user's domain try this
based on task's domain is complex( I think it should currently show only show task's domain related templates only)
this might not work (but try it out)
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
current.addQuery('sys_domain', gs.getUser().getDomainID());
})(current, previous);
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2025 02:22 PM
Hi @SwapnilC
"So, are these agents shared between domains? If yes, then create the template in the Top or MSP domain and use it from there
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]
****************************************************************************************************************