Getting Undefined Value

abirakundu23
Mega Sage

Hi All/  @Murthy Ch ,

Created schedule job that set case assignment to automatically. But adding add() or addDays() logic we get 'undefined' value through log. Could you please help me ?

var caseupdate = new GlideRecord("sn_hr_le_case");
caseupdate.addEncodedQuery('active=true');
caseupdate.query();
gs.info("case test123");
while(caseupdate.next())
{
var date = new GlideDateTime();
gs.info("case test1234");
var date1 = new GlideDateTime(caseupdate.opened_at);
gs.info("case test1245");
gs.info("Created date:" +date1);
var days= date1.add(2);

gs.info("Add days:" +days);    // getting log 'Undefined'
if(date == days && caseupdate.u_country == 'IN')
{

caseupdate.assignment_group = '' ;//sys_id of the group
gs.info("Case assignment successfully");
}
}
gs.info("Case assignment successfully12");

 

11 REPLIES 11

undefined. I am not sure but why it is showing 'undefined' when used with functions like addDays(), addMonths() etc

abirakundu23
Mega Sage

Hi @Sagar Pagar ,

I am still getting the same error message - "Add days: undefined".

 
var date1 = new GlideDateTime(caseupdate.opened_at.toString());
var days= date1.addDaysLocalTime(2);

gs.info ("Add days:" + days); 

Please suggest me.

Community Alums
Not applicable

Hi @abirakundu23 ,

I tried your problem in my PDI and It works for me, please refer below code

var caseupdate = new GlideRecord("sn_hr_le_case");
caseupdate.addEncodedQuery('active=true');
caseupdate.query();
while(caseupdate.next())
{
	var date = new GlideDateTime();
	var date1 = new GlideDateTime(caseupdate.opened_at);
	gs.print("Created date:" +date1);
	date1.addDays(2);
	gs.print("Add days:" + date1.getDate()); 
	if(date == days && caseupdate.u_country == 'IN')
	{
		caseupdate.assignment_group = '' ;//sys_id of the group
		gs.print("Case assignment successfully");
	}
}
gs.print("Case assignment successfully12");

 

Here you are using days varible for prinit which show undefined, you need to print that same variable which you are doing GlideDateTime i.e. date1 and you need to call the method date1.getDate()

 

Result: 

SarthakKashya2_0-1713197625164.png

 

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak

abirakundu23
Mega Sage

Hi @Community Alums ,

Thanks for your update. Now we are getting log after adding addDays().
But these lines of code does not execute.

After if condition log is not executed.

if(date == days && caseupdate.u_country == 'IN')
{
gs.info('Checking date comparison');
caseupdate.assignment_group = ''; //sysid
gs.info("Case assignment successfully");
caseupdate.update();
}
 
Could you please let me know.

Community Alums
Not applicable

Hi @abirakundu23 ,

Reasone behind your code didn't execute if condition is yours days is 2 days extra in opened_at date. It will work after 2 days when date and days value are same.

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak