Closed Krishnanparri closed 6 years ago
@Krishnanparri, change the line
print(workitem[0][Microsoft.VSTS.Common.Activity])
to:
print(workitem[0]['Microsoft.VSTS.Common.Activity'])
and see if that works.
In your case dictionary key should be a string (field name), while otherwise python looks for variable named Microsoft
, which is most likely not present in your code.
@SAnCherepan - still it is not working -
Traceback (most recent call last):
File "C:\QA\Automation\QA_Effort\Project\TFS_update.py", line 58, in
The line
KeyError: 'system.microsoft.vsts.common.activity'
means that the field Microsoft.VSTS.Common.Activity
is not present in a work item.
Either your work item type definition does not contain such field, or the field value in a certain work item is empty (AFAIK, TFS does not return keys for empty fields -> no such key -> exception).
Therefore, the tool tries to find the same field but with the System
prefix (and fails, obviously).
It is implemented this way so you can use e.g. workitem['Title'] instead of workitem['System.Title'].
What I recommend you to do:
System
prefix was auto-included in any fields in older versions).
try:
a = workitem[j]['Microsoft.VSTS.Common.Activity']
except:
print('The wi {id} did not have Activity field, using empty value'.format(id=workitem['ID'])
a = ''
print (a)
should do the trick.
Let us know if it helps.
Thank you @SAnCherepan - I also realized yesterday that TFS work item cannot be blank - and that's what was causing this problem - Sorry for the confusion caused and thanks for the guidance provided - it was really helpful.
Unable print the columns grouped under Microsoft - eg - Microsoft.VSTS.Common.Activity
The Python REPL process has exited Running C:\QA\Automation\QA_Effort\Project\TFS_update.py ('System.Id', 'System.WorkItemType', 'System.Title', 'Microsoft.VSTS.Common.Activity', 'System.AssignedTo', 'Microsoft.VSTS.Scheduling.OriginalEstimate', 'Microsoft.VSTS.Scheduling.RemainingWork', 'System.CreatedDate', 'System.State', 'Microsoft.VSTS.Common.ClosedDate') ('ID', 'Work Item Type', 'Title', 'Activity', 'Assigned To', 'Original Estimate', 'Remaining Work', 'Created Date', 'State', 'Closed Date') 33953,Task,QA : Test Case Creation,Vidya Kulkarni <NYMINT\vkulkarni>,2018-07-05T12:04:08.843Z,Closed Traceback (most recent call last): File "C:\QA\Automation\QA_Effort\Project\TFS_update.py", line 27, in
print(workitem[0][Microsoft.VSTS.Common.Activity])
NameError: name 'Microsoft' is not defined