Service Desk Practitioners Forum
Showing results for 
Search instead for 
Did you mean: 

Retrieving Closed Change Requests on a particular day using web-api

Go to solution
Durga Srinivas
Regular Collector

Retrieving Closed Change Requests on a particular day using web-api

We need to implement the following scenario at our customer site.

1) The list of cLosed Change Requests on a particular Day ( we have
created a custom date field called "Closure Time " for capturing the
closed day details )needs to be displayed in their
internal website.

We are trying to use the web-api (below is the code snippets for your
informaion)for implementing the above scenario.

session =
IChangeHome closedChangeHome = session.getChangeHome();
IChangeWhere closedChangeWhere = closedChangeHome.createChangeWhere();

String closedChangeStatusSring = "Closed";
IStatusChangeHome closedStatusChangeHome = session.getStatusChangeHome();
IStatusChangeWhere closedStatusChangeWhere =
IStatusChange[] allClosedStatusChange =
IStatusChange closedStatusChange=allClosedStatusChange[0];

Date today = new Date();
IChange[] closedChange = closedChangeHome.findChange(closedChangeWhere);

Even though there are some closed Change Requests on a particular day, the
above code is not able to retrieve the Change Requests on a particular
day.And we are suspecting the problem could be due to the reason that the
Date object of Java("today "object in the above code snippets) takes
milliseconds into consideration and also the Custom field "Closure Time"
of Change Request. Hence they are not able to match properly.

So we would like to know how to overcome the this problem?Is there any
methods for Change Request that can be used to retrive
Closed Change Requests on a particular day?

We have SD4.5 with SP14

Thanks in Advance
Chris Bailey_3
Honored Contributor

Re: Retrieving Closed Change Requests on a particular day using web-api


I think that what you want to do is create a date range and use the method ".addCriteriumOnChangeDate1Range(Double[])" rather than just the single double, which is probably trying to do an exact match of the date including milliseconds and all, as you said.

Check out Example5 from the webAPI docs on the install CD. (Or see my attached version). There's a good example of using a calendar, setting a "from" date and a "to" date. In your case, you won't add months to the calendar, but rather probably explicitly set the hours to 0 and 24.

I haven't tested this, but it should be something like HP's with a few modifications:
Calendar cal = Calendar.getInstance();
cal.setTime( new Date() ); //default is today

cal.set( Calendar.HOUR_OF_DAY, 0 );
cal.set( Calendar.MINUTE, 0);
cal.set( Calendar.SECOND, 0);
Date fromDate = cal.getTime();

cal.setTime( new Date() );
cal.set( Calendar.HOUR_OF_DAY, 23 );
cal.set( Calendar.MINUTE, 59);
cal.set( Calendar.SECOND, 59);
Date toDate= cal.getTime();

Double fromBound = ApiDateUtils.date2Double( fromDate );
Double toBound = ApiDateUtils.date2Double( toDate );
Double[] dateRange = new Double[] {fromBound, toBound};


Hope that helps/works. :)

Chris Bailey_3
Honored Contributor

Re: Retrieving Closed Change Requests on a particular day using web-api

Sorry, here is the web-api example as well. Forgot to attach it!
//Add this to "OnDomLoad" event