
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2016 08:53 AM
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?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2016 10:17 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2017 11:48 AM
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