Java Script not working

by Community Manager on ‎04-02-2012 11:14 AM

Question

I'm using a script which will escalate SD to IM While doing so I'm facing an issue below is my script:-

 

var Incident=new SCFile("probsummary");

var relint=new SCFile("screlation");

 

 

record=system.vars.$L_file;

 

// get_sequential_number is not necessary. SM will do it itself.

//Incident.number="IM"+get_sequential_number("incident management");

//print("number in function "+Incident.number);

 

print ("check - 0");

if (record.category =="New Incident")

{

            

           

                  Incident.affected_item=record.affected_item;

                  Incident.brief_description=record.title;

                  Incident.action[0]=record.description;

                  Incident.category=record.category;

                  Incident.contact_name=record.contact_name;

                  Incident.subcategory=record.subcategory;

                  Incident.product_type=record.product_type;

                  Incident.problem_type=record.problem_type;

                  Incident.initial_impact=record.initial_impact;

                  Incident.severity=record.severity;

                  Incident.location=record.location;

                  Incident.dept=record.dept;

                  Incident.contact_name=record.contact_name;

                  Incident.location=record.location;

                  Incident.dept=record.dept;

                  Incident.incident_id=record.incident_id;

                  Incident.zcalltype=record.zcalltype;

                  Incident.logical_name=record.logical_name;

                 

                  var problemtype = new SCFile( "problemtype" );

{

           

                   var selectassign = problemtype.doSelect( "category=\""+ record.category + "\" and limited.given.level2=\"" + record.subcategory + "\" and product.type = \"" + record.product_type + "\" and problem.type = \"" + record.problem_type + "\" and startdate < \""+ record.open_time+"\" and enddate >\""+record.open_time+"\"");

 

print("test1");

 

                  if ( selectassign == RC_SUCCESS )

                  {

                        Incident.assignment=problemtype.assignment;

                  }

                  else

                  {

                        print (RCtoString(selectassign));

                        //return null;

                  }

                 

                       

                  var result= Incident.doAction("add");

                  var d = new XMLDate( new Date() );

                 

                 

                  relint.source=record.incident_id;

                  relint.source_filename="incidents";

                  relint.depend=Incident.number;

                  relint.depend_filename="problem";

                  relint.source_active="t";

                  relint.depend_active="t";

                  relint.sysmoduser="falcon";

                  relint.sysmodtime=d;

                  relint.doInsert();

          

                 

                  if(result==RC_SUCCESS)

                  {

                        print("Your Incident has been logged...");

                        //return result;

                  }

                  else

                  {

                        print("Error...");

                        //return "Error";

                  }

                 

}

}          

 

else

if (record.category !="incident")

{

      print("Your Request has been logged...");

      //return result;

}

    

 

Script is working fine till Im not using the bold portion in below query :-

 

var selectassign = problemtype.doSelect( "category=\""+ record.category + "\" and limited.given.level2=\"" + record.subcategory + "\" and product.type = \"" + record.product_type + "\" and problem.type = \"" + record.problem_type + "\" and startdate < \""+ record.open_time+"\" and enddate >\""+record.open_time+"\"");

 

 

Please help me checking the date issue as open.time of SD record should fall between startdate & enddate(both dates present in problemtype table).

 

I feel the format of the dates open.time of SD & startdate, enddate in problemtype table are not same.

 

Please suggest the way forward to bring the three dates in same format

 

Answer

Try this the date format should be fine now..

 

var d1 = new Date(record.open_time);
d1.setHours(d1.getHours()+5);
d1.setHours(d1.getMinutes()+30);
var d2 = new XMLDate(d1);
var ISOd = d2.getISODay();
var ISOm = d2.getISOMonth();
var ISOy = d2.getISOYear();
var ISOt = d2.getISOTime();
var d = ISOd + "/" + ISOm + "/" + ISOy + " " + ISOt;
var selectassign = problemtype.doSelect( "category=\""+ record.category + "\" and limited.given.level2=\"" + record.subcategory + "\" and product.type = \"" + record.product_type + "\" and problem.type = \"" + record.problem_type + "\" and startdate < '"+ d +"' and enddate >'"+ d +"'");

 

Comments
by Lars_Detmers on ‎12-19-2012 05:38 AM

You should replace \" with '

 

Date formats are:

'01/04/2012 18:11:24'

and not

"01/04/2012 18:11:24"

 

Instead of:

 

 startdate < \""+ record.open_time+"\" and enddate >\""+record.open_time+"\"");

 

Use:

 startdate < '"+ record.open_time+"' and enddate >'"+record.open_time+"'");

 

Hope this helps...

 

Lars

 

 

Search
Follow Us


Twitter Stream
HP Blog

HP Software Solutions Blog

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation