Defects filtered to Initative - rally

looking for help on filtering Defects to initiatives.
I can filter User Stories to Initiative by using the following filter:
var myFilters = [
{
property: 'Feature.Parent.Parent',
operation: '=',
value: selectedInitRef //Initiative Value from Drop Down
},
];
But I cannot seem to get down a level to Defects, below is the hierarchy i use in my subscription.
Initiative
Theme
Feature
User Story
Defect
Any help would be great!

This is now possible with a recent update to WSAPI. In v2.0 the Requirement field on Defect is now of type HierarchicalRequirement. The following filter should now work:
var myFilters = [{
property: 'Requirement.Feature.Parent.Parent',
operation: '=',
value: selectedInitRef //Initiative Value from Drop Down
}];

Related

FaunaDB: how to fetch a custom column

I'm just learning FaunaDB and FQL and having some trouble (mainly because I come from MySQL). I can successfully query a table (eg: users) and fetch a specific user. This user has a property users.expiry_date which is a faunadb Time() type.
What I would like to do is know if this date has expired by using the function LT(Now(), users.expiry_date), but I don't know how to create this query. Do I have to create an Index first?
So in short, just fetching one of the users documents gets me this:
{
id: 1,
username: 'test',
expiry_date: Time("2022-01-10T16:01:47.394Z")
}
But I would like to get this:
{
id: 1,
username: 'test',
expiry_date: Time("2022-01-10T16:01:47.394Z"),
has_expired: true,
}
I have this FQL query now (ignore oauthInfo):
Query(
Let(
{
oauthInfo: Select(['data'], Get(Ref(Collection('user_oauth_info'), refId))),
user: Select(['data'], Get(Select(['user_id'], Var('oauthInfo'))))
},
Merge({ oauthInfo: Var('oauthInfo') }, { user: Var('user') })
)
)
How would I do the equivalent of the mySQL query SELECT users.*, IF(users.expiry_date < NOW(), 1, 0) as is_expired FROM users in FQL?
Your use of Let and Merge show that you are thinking about FQL in a good way. These are functions that can go a long way to making your queries more organized and readable!
I will start with some notes, but they will be relevant to the final answer, so please stick with me.
The Query function
https://docs.fauna.com/fauna/current/api/fql/functions/query
First, you should not need to wrap anything in the Query function, here. Query is necessary for defining functions in FQL that will be run later, for example, in the User-Defined Function body. You will always see it as Query(Lambda(...)).
Fauna IDs
https://docs.fauna.com/fauna/current/learn/understanding/documents
Remember that Fauna assigns unique IDs for every Document for you. When I see fields named id, that is a bit of a red flag, so I want to highlight that. There are plenty of reasons that you might store some business-ID in a Document, but be sure that you need it.
Getting an ID
A Document in Fauna is shaped like:
{
ref: Ref(Collection("users"), "101"), // <-- "id" is 101
ts: 1641508095450000,
data: { /* ... */ }
}
In the JS driver you can use this id by using documentResult.ref.id (other drivers can do this in similar ways)
You can access the ID directly in FQL as well. You use the Select function.
Let(
{
user: Get(Select(['user_id'], Var('oauthInfo')))
id: Select(["ref", "id"], Var("user"))
},
Var("id")
)
More about the Select function.
https://docs.fauna.com/fauna/current/api/fql/functions/select
You are already using Select and that's the function you are looking for. It's what you use to grab any piece of an object or array.
Here's a contrived example that gets the zip code for the 3rd user in the Collection:
Let(
{
page: Paginate(Documents(Collection("user")),
},
Select(["data", 2, "data", "address", "zip"], Var("user"))
)
Bring it together
That said, your Let function is a great start. Let's break things down into smaller steps.
Let(
{
oauthInfo_ref: Ref(Collection('user_oauth_info'), refId)
oauthInfo_doc: Get(Var("oathInfoRef")),
// make sure that user_oath_info.user_id is a full Ref, not just a number
user_ref: Select(["data", "user_id"], Var("oauthInfo_doc"))
user_doc: Get(Var("user_ref")),
user_id: Select("id", Var("user_ref")),
// calculate expired
expiry_date: Select(["data", "expiry_date"], Var("user_doc")),
has_expired: LT(Now(), Var("expiry_date"))
},
// if the data does not overlap, Merge is not required.
// you can build plain objects in FQL
{
oauthInfo: Var("oauthInfo_doc"), // entire Document
user: Var("user_doc"), // entire Document
has_expired: Var("has_expired") // an extra field
}
)
Instead of returning the auth info and user as separate points if you do want to Merge them and/or add additional fields, then feel free to do that
// ...
Merge(
Select("data", Var("user_doc")), // just the data
{
user_id: Var("user_id"), // added field
has_expired: Var("has_expired") // added field
}
)
)

Filtering dstore collection against an array field

I'm trying to filter a dstore collection by a field that has an array of values. My json data looks like the following (simplified):
[{
user_id: 1,
user_name: "John Doe",
teams: [{team_id: 100, team_name: 'Red Sox'}, {team_id: 101, team_name: 'Buccaneers'}]
},
{
user_id: 2,
user_name: "Fred Smith",
teams: [{team_id: 100, team_name: 'Buccaneers'}, {team_id: 102, team_name: 'Rays'}]
}]
I can do a simple filter against the username field and it works perfectly.
this.dstoreFilter = new this.dstore.Filter();
var results = this.dgrid.set('collection', this.dstore.filter(
this.dstoreFilter.match('user_name',new RegExp(searchTerm, 'i'))
));
How, though, do I construct a filter to show me only those players who play for the Red Sox, for example. I've tried using the filter.contains() method, but I can't find any adequate documentation on how it works. Looking at the dstore code, I see that the filter.contains() method has the following signature: (value, required, object, key), but that's not helping me much.
Any guidance would be much appreciated. Thanks in advance!
You can find documentation on Filtering here.
In your case, .contains() will not work because it is intended to work on values of array type. What you want to filter here is array of objects. Here is a quote from the doc link:
contains: Filters for objects where the specified property's value is an array and the array contains any value that equals the provided value or satisfies the provided expression.
In my opinion, the best way here is to override the filter method where you want to filter by team name. Here is some sample code:
this.grid.set('collection', this.dstore.filter(lang.hitch(this, function (item) {
var displayUser = false;
for(var i=0; i < item.teams.length; i++){
var team = item.teams[i];
if(team.team_name == 'Red Sox'){
displayUser = true;
break;
}
}
return displayUser;
})));
this.grid.refresh();
For each user in the store, if false is returned, it's display is set to false and if true is returned it gets displayed. This is by far the easiest way that I know of to apply complex filtering on dstore.
Some similar questions that you might want to read up: link, link, link

Querying (and filtering) in a many-to-many relationship in Backand

I'm trying to use the pet-owner example to create some sort of playlist app where a playlist can be shared among different users.
I have read both links to understand how many-to-many relationship is created in Backand:
Link 1 -
Link 2
According to pet's example, to get all owners from one pet I should get the pet object (using its id field) and then filter its user_pets list matching the user id. That may work for small amount of users/pets but I'd rather prefer to query user_pets table directly by filtering by user_id and pet_id.
My approach has been this code without success:
$http({
method: 'GET',
url: getUrl(), // this maps to pets_owner "table"
params: {
deep: true,
exclude: 'metadata',
filter: [
{ fieldName: 'pet', operator: 'equals', value: pet_id },
{ fieldName: 'owner', operator: 'equals', value: user_id }
]
}
})
Any idea how to query/filter to get only related results?
Thanks in advance
Because user_id and pet_d are both object fields the operator should be "in"
From Backand docs :
following are the possible operators depending on the field type:
numeric or date fields:
-- equals
....
object fields:
-- in

Can Tasks be filtered by Iteration in LookbackAPI?

Here is a store that returns 0 tasks in iteration, even though there are tasks on user stories in iteration 12345. If I use 'HierarchicalRequirement' instead of 'Task' in '_TypeHierarchy', stories are returned. I also tried adding 'Iteration' to the fetch, but it did not help
var snapshotStore = Ext.create('Rally.data.lookback.SnapshotStore', {
autoLoad:true,
fetch : ['Name','_TypeHierarchy'],
filters : [{
property : '__At',
value : 'current'
},
{
property : '_TypeHierarchy',
value : 'Task'
},
{
property : 'Iteration',
value : 12345
}
],
Thank you.
from Rally LBAPI Documentation
The following fields are not available through the Rally Lookback API.
Big/rich text fields (Description, Notes, etc.)
Attachments
Weblink fields
LastBuild, LastRun, LastVerdict on TestCases
Iteration or Release on Tasks
Attributes for all unsupported entities (Workspace, Iteration, Release, Requirement), e.g. Name, EndDate, StartDate on iterations

How to filter by sub-object in Rally 2 SDK

I'm trying to query for user stories whose release start date is greater than a particular date. Is it possible to do this using the "filters" config rather than querying all stories and then checking manually?
Is this valid? :
Ext.create('Rally.data.WsapiDataStore', {
model: 'UserStory',
context: {
project: '/project/xxxx'
},
autoLoad: true,
fetch: ['Rank', 'FormattedID', 'Release'],
filters: [
{
property: 'Release.ReleaseStartDate',
operator: '>',
value: '2012-10-10'
}
]
});
It doesn't work, just fetches all records.
The code posted above does work. I was actually using a comboBox value in the "value" property. Turns out I didn't convert it to a proper DateTime format and hence the comparison was failing and returning all records.
In my case I had to use Rally.util.DateTime.toIsoString in order to compare the value in the combobox.