- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 03:52 AM
Hi All,
Any idea on how to fetch the data of a list type of a field in the article template?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 05:17 AM
I'm assuming you're referring to a Knowledge Base (kb_knowledge_base) record?
The data in the template field takes the form of an encoded query if you look at the XML for the record. See example below:
<template>text=Test^short_description=Testy^EQ</template>
These values could probably be extracted very cleanly using Regex and looking for the sys_ids after the name of the list field field up until the next caret (^) appears but I will leave that for someone else.
A dirtier way to do it would be:
var template = current.getValue('template');
if(template){
var field = 'short_description'; // Template field that we need to extract data for
var fieldIndex = template.indexOf(field + '=');
var fieldDataStartIndex; // Position of the start of the data for the template field
var fieldDataLength; // Length of the data stored against the specified template field
var fieldData; // Stores the data in the specified template field
if(fieldIndex){
fieldDataStartIndex = fieldIndex + field.length + 1; // Correct the value so that it indicates start of data
fieldDataLength = template.indexOf('^', fieldDataStartIndex) - fieldDataStartIndex;
fieldData = template.substr(fieldDataStartIndex, fieldDataLength);
}
}
This is assuming that you did this in the form of a Business Rule on the Knowledge Base table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 05:17 AM
I'm assuming you're referring to a Knowledge Base (kb_knowledge_base) record?
The data in the template field takes the form of an encoded query if you look at the XML for the record. See example below:
<template>text=Test^short_description=Testy^EQ</template>
These values could probably be extracted very cleanly using Regex and looking for the sys_ids after the name of the list field field up until the next caret (^) appears but I will leave that for someone else.
A dirtier way to do it would be:
var template = current.getValue('template');
if(template){
var field = 'short_description'; // Template field that we need to extract data for
var fieldIndex = template.indexOf(field + '=');
var fieldDataStartIndex; // Position of the start of the data for the template field
var fieldDataLength; // Length of the data stored against the specified template field
var fieldData; // Stores the data in the specified template field
if(fieldIndex){
fieldDataStartIndex = fieldIndex + field.length + 1; // Correct the value so that it indicates start of data
fieldDataLength = template.indexOf('^', fieldDataStartIndex) - fieldDataStartIndex;
fieldData = template.substr(fieldDataStartIndex, fieldDataLength);
}
}
This is assuming that you did this in the form of a Business Rule on the Knowledge Base table