- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2016 11:11 AM
i am trying to restrict a variable to only show specific templates. For example in the template i am making an incident template, where the category is 'Request'. In a record producer variable I am trying to add a reference field to only show the templates where the category is 'request'. but i am not able to add that filter in the ref qual that is in the template. how can i restrict this variable to only show where the template 'category' is request?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2016 06:45 PM
You could add a custom field (checkbox) in the sys_template table to check template that are request, then you could use this in your reference qual.
Otherwise, the template field is not well built for condition and doesn't allow you to filter based on contains or something like that.
As for the query data for the template, here is an example of something I used:
var template = new GlideRecord("sys_template");
template.get(sys_id); //Replace sys_id with a variable containing your sys_id for the template
var fieldSets = template.template.split("^"); //First template refers to the GR and second one to the template field
for(e in fieldSets){
if(fieldSets[e] != 'EQ'){ //Removes the EQ which is at the end of the template field value
var field = fieldSets[e].split("=")[0];
var value = fieldSets[e].split("=")[1];
//Then you can either store these field, value pair in an array or use them while you are in the loop
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2016 01:49 PM
Also, what if i wanted to query the data in the template. For example add in the query category = request?
var rec = new GlideRecord('sys_template');
rec.query();
while (rec._next()) {
gs.print(rec.number + ' exists');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2016 06:45 PM
You could add a custom field (checkbox) in the sys_template table to check template that are request, then you could use this in your reference qual.
Otherwise, the template field is not well built for condition and doesn't allow you to filter based on contains or something like that.
As for the query data for the template, here is an example of something I used:
var template = new GlideRecord("sys_template");
template.get(sys_id); //Replace sys_id with a variable containing your sys_id for the template
var fieldSets = template.template.split("^"); //First template refers to the GR and second one to the template field
for(e in fieldSets){
if(fieldSets[e] != 'EQ'){ //Removes the EQ which is at the end of the template field value
var field = fieldSets[e].split("=")[0];
var value = fieldSets[e].split("=")[1];
//Then you can either store these field, value pair in an array or use them while you are in the loop
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2016 06:50 AM
I am not quite following the code example. In a Business Rule i would want to update the checkbox to true when the template has category = request. There would be multiple possible fields/values not just the single one i am looking for. So first wouldn't I be looking at current.template?
- var template = new GlideRecord("sys_template");
- template.get(current.template); //Replace sys_id with a variable containing your sys_id for the template
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2016 05:46 PM
The code example was more to make use of the template you created via server side script which was what I taught you wanted to do when I saw your initial code:
- var rec = new GlideRecord('sys_template');
- rec.query();
- while (rec._next()) {
- gs.print(rec.number + ' exists');
- }
If you want to set the checkbox to true it would be a Insert or Update onBefore business rule on sys_template:
if(current.template.indexOf("category=request") > -1){ //Check if template contains the condition
current.u_name_of_custom_field = true;
}
else{
current.u_name_of_custom_field = false; //Set back to false otherwise as condition could have been removed
}