Get values from template

Vinay49
Tera Expert

Hi 

we have a requirement to update the template values through the script.

 

var grTemplate = new GlideRecord('sys_template');
        grTemplate.addQuery('sys_id','2e43edbfdb155428a497574b6896199c');
        grTemplate.query();
        if(grTemplate._next())
            {
                var string = grTemplate.template.toString();
    
// how can we proceed here to get the value of field  & update the value with new.
               
            }
15 REPLIES 15

Hi @Vinay49 

 

Sorry your screen shot is not clear to me. 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Hi Atul,

can you check here. I want to update the below fields(highlighted in yellow) through script

Vinay49_0-1707394378438.png

 

NaveenGN
Tera Expert

If you want to update a template via template you use the below code

GlideTemplate.get(template.sys_id).apply(GlideRecord)

Please mark correct if you find it useful.

Regards,

Naveen G N

ServiceNow Developer,

Aelum Consulting 

Hi Naveen,

 

Thanks for your reply. can you elaborate more on it. I want to update the below fields(highlighted in yellow) through script

Vinay49_0-1707390300784.png

 

Can you try below code? 

 

 

var gr = new GlideRecord("sys_template");
if(gr.get("acd87481d7930200f2d224837e6103f3")){
    gs.print(gr.template)
   var temp = gr.template+"^state=2"
   gr.template = temp;
   gr.update()
}

 

image.png

Regards,

Naveen G N



please mark correct if you find it correct