How to get Custom Field Values on a Work Item from Devops API - azure-devops

Is there a way to get the values from custom fields that are on a Work Item in devops via the API?
I've tried both the $expand=all and fields options from the Get Work Items API and couldn't get the data I was looking for. When trying with the fields option, I tried with both name and referencename values from the Fields API without success.
Thanks.

Yes. Use simple "GET WORK ITEM" API:
GET https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/{id}?api-version=6.0
Note, you will only be able to see the custom field (or even any other field) in the JSON response as long as that field has a value stored to it on that work item.

If you just want to get a filed value of specific work item, simply use WIQL and client library.
For example , if your work item have some custom fields and you could try to get these fields by querying with WorkItemCollection, like this:
WorkItemCollection queryResults = workItemStore.Query("Select [State], [Work Item Type], [Title], [Resource Development], [Customize.Complexity.Development] FROM WorkItems " +
"WHERE [Work Item Type] = '" + tipoWorkItem + "' AND [State] <> 'Closed' AND [Team Project] = '" + teamProjectName + "'");
Finally get the custom fields by looping the result, like this:
foreach (WorkItem workItem in queryResults)
{
variable = workItem.Fields["Customize.Resource.Development"].Value;
}
For more details you could also take a look at this similar question: How to get Whats New field value from TFS

Related

Refine Search on WIQL

WIQL SEARCH:
{
"query": "SELECT [System.Id] FROM WorkItems WHERE [System.Title] Contains Words 'midserver' AND [System.AreaPath] = 'XXXXX' AND [System.WorkItemType]='Issue' AND [System.State]<>'Done' ORDER BY [System.Id]"
},
can you pls help me with a query which refines the search i.e. the query should search the exact words and not CONTAINS ([System.Title] CONTAINS 'Search Text') –
something like IS ([System.Title], i have tried that but it doesn't recognize the query i think "IS" is not recognized
for e.g. story contains following names "rahul 1", and "rahul 2"..but if Iam searching with only "rahul" it should not display "rahul1" and "rahul2" instead it should say something like not found
Observation: its not working if there is space in the user story when i use Contains Words
so basically searching for the exact text if it is there or not but not search with contains
Since you want to search the exact words, why not just use a " = ". Change your WIQL like this:
SELECT
[System.Id]
FROM WorkItems
WHERE
[System.Title] = 'midserver'
AND [System.WorkItemType]='Issue'
AND [System.State]<>'Done'
ORDER BY [System.Id]
Actually the detail supported operators you are using such as =, Contains, Under is based on Field type.
Not all operators could used for each field type. For details, you could take a look at this screenshot:
If you are using System.Title which is a string field
Title
A short description that summarizes what the work item is and helps
team members distinguish it from other work items in a list. Reference
name=System.Title, Data type=String
So instead of Contains Words, you could directly use "=" in your case. For other kind of fields, you need to follow above operators.

MS Access Multiple Instances of Single Form for different clients

Another question that stumps me.
I have a continuous form that shows a list of all of our clients at the law firm I work at here. Right now you can double click on a client name where a form (frmContactSummary) then opens up to display all the information for that client.
Problem is, as it is currently designed only one form can be open for a client at a time.
We want to be able to open multiple versions or instances of frmContactSummary.
I borrowed code from Allen Browne's site, which is as follows:
Option Compare Database
Option Explicit
'Author: Allen J Browne, July 2004
'Email: allen#allenbrowne.com
'Found at: http://allenbrowne.com/ser-35.html
Public clnClient As New Collection 'Instances of frmClient.
Function OpenAClient() 'ContactID As Integer
'Purpose: Open an independent instance of form frmClient.
Dim frm As Form
'Debug.Print "ID: " & ID
'Open a new instance, show it, and set a caption.
Set frm = New Form_frmContactSummary
frm.Visible = True
frm.Caption = frm.Hwnd & ", opened " & Now()
'Append it to our collection.
clnClient.Add Item:=frm, Key:=CStr(frm.Hwnd)
Set frm = Nothing
End Function
This works in a way, but it only opens up the first record in our Contact table. We want the instance to open on a specific record, or ID from the Contacts table.
I tried this code near the end:
frm.RecordSource = "select * from Contacts where [ID] = " & ContactID
But it did not work.. :-(
Any advise would be much appreciated! Thank you!
Ok, when you create a instance of a form, you can’t use the common approach of a where clause like this:
Docmd.OpenForm "frmContactSummary",,,"id = " & me!id
The above of course would work for opening one form.
However, in your case, you need:
Create a new instance of the form
Move/set the form recordsource to ID
Display the form
So we need a means to move or set the form to the ID of the row we just clicked on.
So right after we create the form, then add this line of code:
Set frm = New Form_frmContactSummary
Frm.RecordSource = "select * from Contacts where id = " & me!id
And rest of your code follows.
It not clear if the PK (key) of the table Contacts is “id”, or “ContactID”
So your code will be:
Frm.RecordSource = "select * from Contacts where id = " & me!id
Or
Frm.RecordSource = "select * from Contacts where Contactid = " & me!ContactID
Simply replace “ContactID” in above with a actual PK id used in table contacts. The "Id" has nothing to do with the collection. We are simply building a SQL statement that will pull/set the form to the one row. So the only information required here is what is the PK name in your continues form, and what is the PK name in your frmContactsSummary. (they will be the same name in both forms, and should thus be the same in the sql statement.

Access 2007 VBA: use Form.Filter in query parameters

I'd like to create and open a select query based on the user's current form filters. I can do this in VBA by parsing the form's Me.Filter string, extracting the bits I need and building a WHERE statement. However, putting in the all the required logic, punctuation and syntax is going to be a pain.
So my question, before I do all that is: is there any existing function to do this?
Thanks.
Maybe my comment was a little cryptic.
Let's say the recordsource of your form is myQuery.
The form is filtered, Me.Filter = myQuery.field1 LIKE 'asdf*' AND myQuery.field2 = 42
So your select query is e.g.
SELECT field1, field3
FROM myQuery
WHERE myQuery.field1 LIKE 'asdf*' AND myQuery.field2 = 42
or
myQuerydef.SQL = "SELECT field1, field3 FROM " & Me.Recordsource & _
" WHERE " & Me.Filter
So I don't quite see where the problem is.
The answer to your question is no, there is no function - but you shouldn't need anything besides Me.Filter.
Edit as suggested by HansUp:
If the RecordSource of your form currently isn't a single query, but a SELECT statement, create a named query from that SELECT statement, and use that query as RecordSource.

simple where clause SSRS 2005 parameter not working

this should be a simple thing but I've spent hours to no avail. Basically, I need to look up a salesrep # in a SQL database using the user's Window's user id. The format of the user id is
"Norstar\kjones" and I need the "kjones" portion of it.
using the split function, I am able to pull just the 'kjones' part out:
split(User!UserID,"\").GetValue(1)
I've created a parameter called SlsmnNum and created a dataset to be used to look up the salesrep # using the user id (the slsm_num field is a varchar, not an integer):
select slsm_num from Salesman_Msid where slsm_msid = ''' + split(User!UserID,"\").GetValue(1) + '''
However, I get no results. How can I get the select to work?
alternatively, I tried the following:
in parameter SlsmnNum, I set the default to an expression using:
split(User!UserID,"\").GetValue(1) and this returns 'kjones', as expected.
I created a SECOND parameter (which is positioned BELOW the SlsmnNum parameter), SlsmnNum2, that has a default (and an available) value using a query, which is a dataset containing the following select statement:
select slsm_num from Salesman_Msid where slsm_msid = (#SlsmnNum)
When I run the query on the Data tab, when I type in 'kjones' into the parameter box, it returns '1366', the salesrep # I'm expecting.
But, when I Preview the report, all I get in SlsmnNum2 box is Select a Value and nothing is there (it should return '1366').
Any help would be greatly appreciated!
Try your first approach with Query Text as
="select slsm_num from Salesman_Msid where slsm_msid = '" & split(User!UserID,"\").GetValue(1) & "'"

wordpress 3.2.1 database query

i am trying to make a simple selection in a wordpress table (created by a plugin). the table is named reduceri , and has the following columns: id, post, category.
so, i am trying to take all the category values, when the post is equal to the current post id.
the way i am doing the query is:
$the_query = "
SELECT $wpdb->reduceri.category
FROM $wpdb->reduceri
WHERE $wpdb->reduceri.post = ".$post_id."
";
$my_reduceri = $wpdb->get_results($the_query);
but when i var_dump the $my_reduceri all i get is an empty array: array(0) { } even though there should actually be some results... any idea where i am wrong (in the query)?
thank you
Did you declared global $wpdb; before using this query?