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

Inactive_Us1474
Giga Guru

Are you able to get the log messages and what value is coming?


log message not taking the values it simply returning "get template value"       massage without value



gs.log("get template value"+templateList);


Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

Take a look at this blog post. Here Im using the applyTemplate() to apply incident templates that were chosen at the call to apply on the created incident.



Using incident templates direct from calls



//Göran


Have a look at the script I posted here: how to remove creation of two same record in the backend in the change request



This does pretty much what you need.