Use PDIs? Take our 5-minute survey to help shape the PDI roadmap.

How is update function works in server side script?

praveensnow9984
Tera Contributor

How is update function works in server side script

3 REPLIES 3

Ankur Bawiskar
Tera Patron

@praveensnow9984 

which update method you are referring?

GlideRecord update?

if yes then it simplys updated the record with the fields you set just before using the update() method

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

SohamTipnis
Mega Sage

Hi @praveensnow9984,

 

 

In ServiceNow scripting, how the update() function works depends on the context you are using it in. There are two completely different types of "update" functions in ServiceNow server-side architecture: 
 
 

 

  • gr.update() (GlideRecord API): Used to save record changes directly to the database.

 

 

  • c.server.update() / server.update() (Service Portal API): Used to trigger a server-side refresh or pass data from a Service Portal widget's client controller to its server script.

 

 

If you find my answer useful, please mark it as helpful and correct. ‌‌😊


Regards,
Soham Tipnis
ServiceNow Developer || Technical Consultant
LinkedIn: www.linkedin.com/in/sohamtipnis10

yashkamde
Giga Sage

Hello @praveensnow9984 ,

 

The GlideRecord update() method is used in backend like Business Rules, Script Includes, and Background Scripts. It saves changes made to a record back into the database.

 

Calling .update() commits those adjustments directly to the ServiceNow database.

 

for ex :

// Example in a Background Script or Script Include
var gr = new GlideRecord('incident');
if (gr.get('sys_id_of_the_record')) { 
    gr.short_description = 'Updated via Server Script';
    gr.update(); //Commit and trigger system engines
}

 

Additionally we have c.server.update() : Service Portal Communication -

In Service Portal Widgets, c.server.update() is a client-side controller method that triggers execution of the widget's server-side script.

 

If my response helped mark as helpful and accept the solution.