How to get template values

kamleshrathore
Kilo Contributor

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];

  }

}

find_real_file.png

find_real_file.png

here once if i select the template then configuration item and assignment group.should populate into this fields

8 REPLIES 8

Sri Harsha3
Tera Expert

Did you found the solution for this? Please let me know the way to solve this issue.

Paul Kunze
Tera Guru

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]);
  }
}

What about caret ^ and equals = characters embedded in the values? That will screw up this code.

this works great.