How to get template values
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2016 12:56 PM
hi team
i have record producer which having field template ,this template consist two field configuration item and assignment group
i have written below code in record producer script to populate the fields value into the configuration item and assignment group.
in the below i want to get the template value and i want to store the the number of filelds into separate variable and that value i want to
populate into configuration item and assignment group.
but in the below code i am not able to get the template value and not able to do put into array and
how to populate this values into configuration item and assignment group.
so please provide me your code
except appyTemplate method because if i am using applytemplate method
then there is two same number record is going to create
var templateList = "";
var splitListFields = "";
var seperateFiled_Values = "";
var grGlide = new GlideRecord("sys_template");
grGlide.addQuery("name",producer.u_template.name);
grGlide.query();
gs.log("get count row"+grGlide.getRowCount());
if(grGlide.next())
{
templateList = grGlide.getValue("template");
}
gs.log("get template value"+templateList);
if(templateList != "")
{
splitListFields = templateList.split("^");
}
gs.log(splitListFields+"get the length "+splitListFields.length);
for(var i=0;i<splitListFields.length;i++);
{
seperateFiled_Values = splitListFields.split("=");
gs.log("get the field "+seperateFiled_Values[0]+"get the value "+seperateFiled_Values[1]);
if(seperateFiled_Values[1] != "")
{
current.seperateFiled_Values[0] = seperateFiled_Values[1];
}
}
here once if i select the template then configuration item and assignment group.should populate into this fields
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2019 03:00 AM
Did you found the solution for this? Please let me know the way to solve this issue.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-25-2019 07:03 AM
You need to remove that semicolon in the for loop and add [i] behind splitListFields:
...
for(var i=0;i<splitListFields.length;i++)
{
seperateFiled_Values = splitListFields[i].split("=");
...
This is all the code you need:
var templateList = "";
var splitListFields = "";
var separateFieldValues = "";
var grGlide = new GlideRecord("sys_template");
grGlide.addQuery("name", producer.u_template.name);
grGlide.query();
if(grGlide.next()){
templateList = grGlide.getValue("template");
}
splitListFields = templateList.split("^");
for(var i = 0; i < splitListFields.length; i++){
if(splitListFields[i].includes("=")){
separateFieldValues = splitListFields[i].split("=");
current.setValue(separateFieldValues[0], separateFieldValues[1]);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 04:26 AM
What about caret ^ and equals = characters embedded in the values? That will screw up this code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2022 09:02 AM
this works great.