Service Desk Practitioners Forum
cancel

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

SOLVED
Go to solution
Highlighted
Durga Srinivas
Respected Contributor.

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 =
ApiSDSession.openSession(,,);
IChangeHome closedChangeHome = session.getChangeHome();
IChangeWhere closedChangeWhere = closedChangeHome.createChangeWhere();

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

Date today = new Date();
closedChangeWhere.addCriteriumOnChangeDate1(ApiDateUtils.date2Double(today));
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
Srini
2 REPLIES
Chris Bailey_3
Outstanding Contributor.

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

Hello,

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 example5.java 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};

closedChangeWhere.addCriteriumOnChangeDate1Range(dateRange);
----------------------------------------------

Hope that helps/works. :)

Thanks,
Chris
Chris Bailey_3
Outstanding Contributor.
Solution

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!