Shantha - Tuesday, February 12, 2013 12:57 AM:
Hi Team,
I m trying to compare the expiry date with todays date and the day differences will get updated in field date_diff if the day is less than 30days then the bar_no(one Property of the Itemtype) should be emailed to the manager stating this bar_no is going to be expired soon, is my task this should happen everyday so i m trying to write schedular job. I wrote server side method C#.
Innovator inn = this.getInnovator();
Item st_base = this.newItem("st_Issue_Instrument","get");
Item results = st_base.apply();
int count = results.getItemCount();
for (int i=0; i<results.getItemCount(); ++i)
{
Item st_compare = this.newItem("st_Issue_Instrument","get");
string ExpiryStr;
ExpiryStr=st_compare.getProperty(st_base.getItemByIndex(i).getProperty("expiry_date"));
if(ExpiryStr=="")
{
return this;
}
else
{
DateTime theDate;
theDate = DateTime.Now;
DateTime startDt =(theDate);
DateTime endDt = DateTime.Parse(ExpiryStr);
if (DateTime.Compare(endDt, startDt) <= 0)
{
Item err = inn.newError("Your finish date must be greater than your start date!!!");
return err;
}
else
{
TimeSpan dateDiff = endDt - startDt;
int days = dateDiff.Days;
int hours = dateDiff.Hours;
int minutes = dateDiff.Minutes;
float hoursTotal = ((float)days*24) + (float)hours + ((float)minutes/60);
this.setProperty("date_diff",hoursTotal.ToString());
this.setProperty("date_diff",days.ToString());
string datediff = this.getProperty("date_diff","");
}
}
}
return this;
This method name i call in Schedular" Innovatorconfig.xml" and make this to call the method every day 5AM so that it runs takes updated day difference .
Above the underlined code is not excuting i dont know why, can you anyone guide me where im doing error.Thanks in advance.
Thanks,
Shantha.
Eric Domke - Wednesday, February 13, 2013 8:49 AM:
Why do you need the st_compare variable? It seems that the underlined line and the two above it could be condensed down to:
string ExpiryStr = st_base.getItemByIndex(i).getProperty("expiry_date", "");
As a side note, the TimeSpan structure already has a TotalHours property (msdn.microsoft.com/.../system.timespan.totalhours.aspx) which makes your calculation of the total hours redundant.