Help on "this" keyword in script include.

SunilKumar_P
Giga Sage

Hello,

 

Can someone explain me on what scenarios do we use "this" in scrip include? I am aware that in the Ajax call we will use this.getParameter but I have also "this" key word for the sever call Script include.

Ex: this.user = request.caller_id;

I would like to understand on what cases/scenarios do we need to use "this" keyword?

 

Thanks,

Sunil

5 REPLIES 5

Imran1
Giga Guru

Hi,

I am using the value of this in my GlideRecord which I have called it under the initialize script include area. Now the requirement is to set the value of (this.) to a date field. which is not happening

I tried JSON.stringify() to get the value in string and set it in GlideDate() but it doesn't work. I still get the result as object.

How to do the extraction and set the value into the field.

var UniqueUser = Class.create();
UniqueUser.prototype = {
initialize: function() {

this.start = this.startDates();
this.end = this.EndDates();

},

startDates: function() {
var startDate = new GlideDate();
//startDate.setValue('2020-07-01');
startDate.setDayOfMonthUTC(1);
return startDate;
},
EndDates: function() {
var endday = this.start.getDaysInMonthUTC();
var endDate = new GlideDate();
//endDate.setValue('2020-07-21');
endDate.setDayOfMonthUTC(endday);
return endDate;
},

Recipients: function() {
gs.info('Receipients:');
var recep = [];
var uniqueArray;
var gr = new GlideRecord('sys_email');
gr.addNotNullQuery('recipients');
gr.query();
while (gr.next()) {
var emails = gr.recipients.toLowerCase().toString().split(",");

for (var i = 0; i <= emails.length - 1; i++) {
recep.push(emails[i]);
}

}

uniqueArray = new global.ArrayUtil().unique(recep);
var nonUser = NonUsersX(uniqueArray);

var myJSON = JSON. stringify(this.start);
var startMonth = new GlideDate();
startMonth.setValue(myJSON);

gs.info('TypeOf: '+typeof(startMonth)); // Still returns as object, I was expecting it to be a date, not sure how to set the object into a date field

function NonUsersX(uniQue) {
if (uniQue.length > 0) {
for (var i = 0; i < uniQue.length; i++) {
var Usr = new GlideRecord('sys_user');
Usr.addQuery('email', uniQue[i].toString());
Usr.query();
if (!Usr.next()) {
var dupCheck = new GlideRecord('u_non_userX');
dupCheck.addQuery('u_email', uniQue[i].toString());
dupCheck.addQuery('u_month', this.start);
dupCheck.query();
if (!dupCheck.next()) {
var uniUser = new GlideRecord('u_non_userX');
uniUser.initialize();
uniUser.u_email = uniQue[i].toString();
uniUser.u_month = startMonth; // This is were I am setting the value of this. which should be 2020-07-01
//uniUser.u_month = uniQue[i]["sys_created_on"];
uniUser.insert();
gs.info("RecordsCreated: "+startMonth);
}
}
}
}
}

},

Any help to resolve this is much appreciated.

Regards,
Imran