onChange script error: ReferenceError: GlideTemplate is not defined function () { [native code] }

scsn
Tera Contributor

I am applying a Tamplet when "Type of Project Field" changes to A.

I am getting error message like this.

 

onChange script error: ReferenceError: GlideTemplate is not defined function () { [native code] }

 

My Client script is as given below.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

   //Type appropriate comment here, and begin script below

   if(g_form.getValue('u_type_of_project') == 'A' )
   {
        var newRec= new GlideRecord('pm_project');
        newRec.initialize();

        // Apply the template using the GlideTemplate API
        var template = GlideTemplate().get('51597e3b979e75507110d6081153affa');
        if(template != null){
        template.apply(newRec);
        }
        newRec.insert();
   
    }
}

 

Pleae gide.

 

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@scsn 

do this

1) use after update BR on your table with condition as Field Changes to A

(function executeRule(current, previous /*null when async*/) {

	// Add your code here

	var newRec= new GlideRecord('pm_project');
	newRec.initialize();
	GlideTemplate.get('51597e3b979e75507110d6081153affa').apply(newRec);

})(current, previous);


If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

 

 

scsn_0-1699866731082.png

 

 

(function executeRule(current, previous /*null when async*/) {

    // Add your code here

if(g_form.getValue('u_type_of_project') == 'A' )
    {
        var newRec= new GlideRecord('pm_project');
       
        newRec.initialize();

        // Apply the template using the GlideTemplate API

        //var template = GlideTemplate().get('51597e3b979e75507110d6081153affa');

        GlideTemplate.get('51597e3b979e75507110d6081153affa').apply(newRec);

        if(template != null){
        template.apply(newRec);
        }
        newRec.insert();
   
    }

})(current, previous);

scsn
Tera Contributor

Nothing is happning

 

scsn
Tera Contributor

AM I missing somethng ?