- 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-23-2018 05:48 AM
There is a problem in this when you get the = character in the field or value it won't work as expected is there any alternate solution there..?
I have an HTML data for one field and it has = character and it's breaking up to there.
the actual data is: <p><span style="color:green">test</span></p>
Please see the screenshot for ref:
Help is appreciated thanks
If anyone wants client side split script to check this one but the issue is still not fixed yet.:
//oneline string to object starts here
function get_json_from_string(x) {
var ob = {};
if(x){
var a = x.split("^");
for( i = 0 ; i < a.length ; i++){
var t = a[i].split('=');
ob[ t[0] ] = String(t[1]);
}
}
return ob;
}
//oneline string to object ends here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2018 07:01 AM
Hi Abdul,
I've written this answer a long time ago, since then I rebuilt a similar function using an OOB function being used in the Standard change module. In you use case here is what it would look like:
function get_json_from_string(x) {
if(x) {
x = x.trim();
var attributeList = x.split('^');
var ob = {};
for (var i = 0; attributeList && i < attributeList.length; i++) {
var firstIndex = attributeList[i].indexOf('=');
if (firstIndex > -1) {
ob[attributeList[i].substring(0, firstIndex)] = attributeList[i].substring(firstIndex + 1).trim();
}
}
return ob;
}
return {};
}
However, this still does not solve an issue that could occur if "^" was part of the string.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2018 11:19 AM
Please refer if you want a solution in clientside instead of serverside.
https://stackoverflow.com/questions/50491026/split-string-from-start-to-end-like-object