getGlideObject() Usage

Kalaiarasan Pus
Giga Sage

So, this is a interesting question and I haven't noted this earlier.

I was answering on one of the thread and used getGlideObject() to add few years using another field of the same table.

var gr = new GlideRecord('alm_hardware');

gr.query('asset_tag', 'P1000479');

if (gr.next()) {

var warranty =   gr.assigned.getGlideObject();

warranty.addYears(1);

gr.install_date=warranty;

gr.setWorkflow(false);

gr.update();

}

The above script looks very innocuous. But instead of updating install date alone, it also updated the assigned date.

Is it because we are actually manipulating on the original glideobject within the current scope instead of a localized value?

1 ACCEPTED SOLUTION

Hi Kalai,



I believe this happens because of object inheritance, which causes any change to an object to also change any object it references through its prototype chain.


When you stored the object in warranty, it still contains the reference to the original object, thus it also gets changed.


View solution in original post

5 REPLIES 5

johnram
ServiceNow Employee
ServiceNow Employee

The ServiceNow Wiki content is no longer supported. Updated information about this topic is located here: GlideDateTime



 


Visit http://docs.servicenow.com for the latest product documentation