
- 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
04-20-2016 12:43 AM
Bump. Anyone ? pradeepksharma mguy Can you guys take a look at this question?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2016 01:09 AM
I think, this is just a guess to be fair, that because you are getting the 'assigned' object and then you are adding a year to it, you are actually telling the tool to update that object.
what maybe you could do is
var gdt = new glideDateTime(gr.assigned);
GlideDateTime - ServiceNow Wiki
so that declares gdt as the object, not the actual field and then you can do the addYears to gdt and apply it to install_date.
Marc

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2016 02:04 AM
Thank you for the response.
At the end, I did do as suggested by you but was just curiously and surprised with the way getGlideObject object worked ..

- 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.