mongodb spring data Projection project only date component without time component - mongodb-query

mongodb spring data Projection project only date component remove existing time component.
Spring data mongoOperation in which i want to project my date[that is with time] to only date and group on it.
but i am not able to project it.
That i further need to group data on.
Aggregation aggregation = Aggregation.newAggregation(NucleusFunctionSpaceGuestRoomPace.class,
Aggregation.match(Criteria.where("propertyId").is(propertyId).
andOperator(
Criteria.where("lastModifiedDate").lt(endDate),
Criteria.where("lastModifiedDate").gte(startDate)
)),
sort(Sort.Direction.ASC, "propertyId")
.and(Sort.Direction.ASC, "bookingId")
.and(Sort.Direction.ASC, "roomType")
.and(Sort.Direction.ASC, "stayDate")
.and(Sort.Direction.DESC, "lastModifiedDate")
,
Aggregation.project().and("propertyId").as("propertyId")
.and("bookingId").as("bookingId")
.and("roomType").as("roomType")
.and("stayDate").as("stayDate")
.and("bookingPaceId").as("bookingPaceId")
.and("roomNights").as("roomNights")
.and("guestRoomStatus").as("guestRoomStatus")
.and("lastModifiedDate").as("lastModifiedDate")
.andExpression("year(lastModifiedDate)").as("year")
.andExpression("month(lastModifiedDate)").as("month")
.andExpression("dayOfMonth(lastModifiedDate)").as("month")
);

Related

Extract incident details from Service Now in Excel

I am trying to extract ticket details from Service Now. Is there a way to extract the details without ODBC ? I have also tried the solution mentioned in [1]: https://community.servicenow.com/docs/DOC-3844, but I am receiving an error 9 -subscript out of range.
Is there a better way to extract details efficiently? I tried asking this in the service now forum but I thought I might get other opinions from here.
It's been a while since this question is asked. Hopefully following is still useful.
I am extracting change data (not incident) , but the process still should be same. You will need to gather incident table and column information. Then there are couple of ways to approach the problem.
1) If the data you are extracting has fixed parameters , such as fixed period or fixed column or group etc., then you can create a report within servicenow and then use REST/SOAP API to get the data in text/csv format. You can use different python modules to convert from csv to xls or xlsx depending on you need. I used openpyXL ,csv , xlsreader ,xlswriter etc.
See here for a example
ServiceNow - How to use SOAP to download reports
2) If the data has dynmaic parameters where you need to change columns, dates or filter etc, you can still use soap / REST API but form query within python scripts instead of having static report. This way you can change it based on your requirement on the fly.
Here is an example query for DB. you can use example for above. Just switch url with following.
table_name = 'u_change_table_name' #SN DB holding change/INCIDENT info
table_limit = 800
table_query = 'active=true&sysparm_display_value=true&planned_start_date=today'
date_query = 'chg_start_date>=javascript:gs.daysAgoStart(1)^active=true^chg_type=normal'
table_fields = 'chg_number,chg_start_date,chg_duration,chg_end_date' #Actual column names from DB and not from SN report.
url= (
'https://yourcompany.service-now.com/api/now/table/' +table_name +\
'?sysparm_query=' + date_query + '&sysparm_fields=' \
+ table_fields + '&sysparm_limit=' + str(table_limit)
)

Scribe Jobs: how to get the current date and compare it?

Honesty I'm very new in terms of Scribe Jobs, but I have been trying to develop a Job that get the current date and compare it against one field from the source (CRM input Date).
This is the code in the formula editor of the Pre-Operation Step Control:
IF(S146 =TODAY( ), GOTOSTEP ( ),FAILROW( ))
I'm trying to allow the migration only for records inserted today, the rest will just generate error.
Can somebody help me?
Try this:
if( DATEDIFF ("d", GETCURRENTUTCTIME, S146) < 1 )
Here's a great place to look for more information:
http://help.scribesoft.com/scribeonline/en/sol/formulas/datefunctions.htm

API: Querying TestCaseResults with project scoping?

Is it possible to query for testcase results using project scoping?
The TestCaseResult object does not contain a project scope, and queries for testcaseresults seem to ignore project scoping.
So is there a way to, for example, to query for all test case results in the last 14 days scoped under a particular project and its children projects?
In standard WSAPI, you can do:
((TestCase.Project.Name = "My Project") AND (CreationDate > "2013-01-07"))
or
((TestCase.Project.ObjectID = "12345678910") AND (CreationDate > "2013-01-07"))
on TestCaseResults and it should provide you with Project-scoped TCR's.
If you desire child projects, you'd need to either run multiple queries, or do some complicated AND'ing.

Rally web service API: Retrieve Test Cases base on Iteration or WorkProduct attributes

I try to retrieve test cases from rally using XML URL such as
https://rally1.rallydev.com/slm/webservice/1.37/testcase?query = ...
I want to retrieve only test cases of WorkProducts those are accepted from day x to day y so I build the query like this:
https://rally1.rallydev.com/slm/webservice/1.37/testcase?query=((WorkProduct.AcceptedDate >= "yyyy-mm-dd") AND (WorkProduct.AcceptedDate <= "yyyy-mm-dd"))
The result is: Could not traverse to "AcceptedDate"
The funny thing is I can do something like:
https://rally1.rallydev.com/slm/webservice/1.37/testcase?query=(WorkProduct.LastUpdateDate <= "2012-06-26")
which is the same concept.
Is there anyone can say why LastUpdate information is query-able and AcceptedDate is not?
Thanks,
Minh Tue
The reason this doesn't work is because the WorkProduct field on TestCase is an Artifact. Artifact does have a LastUpdateDate field but does not have an AcceptedDate field. You should still be able to get the data you want but it will take a few extra queries.
You'll have to query for defects and stories whose AcceptedDate is in the desired range and include TestCases in the fetch.

How do you query a ravendb index containing dates using Lucene?

I am using the http api to query ravendb (so a LINQ query is not the solution to my question).
My Product document looks like this:
{
"editDate": "2012-08-29T15:00:00.846Z"
}
and I have the index:
from doc in docs.Product
select new { doc.editDate }
I want to query all documents before a certain date AND time. I can query on the DATE using this syntax:
editDate: [NULL TO 2012-09-17]
however I can't figure out how to query the time component as well.
Any ideas?
You can query that using:
editDate: [NULL TO 2012-09-17T15:00:00.846Z]
If you care for a part of that, use:
editDate: [NULL TO 2012-09-17T15:00]
Note that you might have to escape parts of the query, like so:
editDate: [NULL TO 2012\-09\-17T15\:00]
For this to work you also need to ensure that the field is analysed.
In Raven Studio - Add Field -> editDate, and set Indexing to Analyzed.
One way of working around this problem is to store the value not as a date but as the number of seconds since the unix epoch.
This results in a number that you can compare against with ease.
I am using javascript and the moment js library:
{
"editDate": "2012-08-29T15:00:00.846Z",
"editDateUnix": moment("2012-08-29T15:00:00.846Z").unix()
}
Any my index:
from doc in docs.Product
select new { doc.editDate, doc.editDateUnix }
and my lucene query:
"editDate: [NULL TO "+moment("2012-09-17").unix()+"]"