Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Vinay49 

What is use case to update template from script. Do it  via interface.

*************************************************************************************************************
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,


There is a fix script that will change the URL and certificate for GRIP related IDP's.

Other functionality in the integration is that is we receive a message, and IDP will automatically be created, based on a template that is used. here IDP is created with old values.

So, My requirement is, If the script is execute also the template must be changed.
 So that i have added above script in my fix script to update the new values. 

 

Hi @Vinay49 

 

Thanks for update. Try this manner

 

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

*************************************************************************************************************
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,

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

Vinay49_0-1707393272442.png