- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2016 08:37 AM
Will anyone please help me to understand what is the significance of this keyword. Most of the time i see this keyword whenever we call server side call from client side[Glide Ajax]. please give some simple example for better understanding.
Thanks In Advance...
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2016 10:22 AM
Hi Arun,
This refers to the current context object. For example within DateTimeUtils
var DateTimeUtils = Class.create();
DateTimeUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
initialize: function() {
this.nowTime = new GlideDateTime("02/21/2016");
},
msToGlideDateTime : function() {
var ms = this.nowTime;
var gDate = new GlideDateTime();
gDate.setValue(parseInt(ms, 10));
return gDate;
}
);
If you notice in msToGlideDateTime, I am using this.nowTime defined above in initialize function. Here this refers to DateTimeUtils Object.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2016 10:22 AM
Hi Arun,
This refers to the current context object. For example within DateTimeUtils
var DateTimeUtils = Class.create();
DateTimeUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
initialize: function() {
this.nowTime = new GlideDateTime("02/21/2016");
},
msToGlideDateTime : function() {
var ms = this.nowTime;
var gDate = new GlideDateTime();
gDate.setValue(parseInt(ms, 10));
return gDate;
}
);
If you notice in msToGlideDateTime, I am using this.nowTime defined above in initialize function. Here this refers to DateTimeUtils Object.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2016 10:35 AM
Hi Venkat
Thanks for your response. I have also find one example that might help others to understand the this variable concept .
Point: - You can add functions and properties to existing objects in this manner
The "this" variable is actually the GlideRecord object!
Navigate to System Definition -> Script Include.
Name: GlideRecordExtensions
Script:
GlideRecord.prototype.toObjectList = function() {
var objectList = [];
// loop through all the records and create the object array
while(this.next()) {
objectList.push(this.toObject(this));
}
this.restoreLocation(); // set it back to the beginning so that we can use if for other things
return objectList;
};
-----------------------------------------------------------------------------------------------------------------------------------------------------------
gs.include('GlideRecordExtensions');
var incidents = new GlideRecord('incident');
incidents.addActiveQuery();
incidents.setLimit(10);
incidents.query();
gs.print(incidents.getRowCount());
Now invoke our new GlideRecord extension!
var stuffList = incidents.toObjectList();
Here this refers to incidents which is a glide record object.
I hope this will help others to understand this concept