*This post is locked for comments
*This post is locked for comments
WorkItemProxy isn't a system class, it's a .NET class. You should be able to simply use IntelliSense to see its public methods and properties, or open the assembly in object browser in Visual Studio or even decompile the code. But the best approach may be running the code in CIL and examining workItem object in Visual Studio debugger.
Nevertheless it seems that you successfully get AssignedTo property via reflection, right? The comment in your code suggests that the problem lies in GetValue().
The second piece of code is guaranteed to throw an error, because you try to call a method on a null object.
Regarding code pasting, this is how it should look like when you use the </> button in the rich formatting view:
propInfo = clrWorkItemType.GetProperty('AssignedTo'); if (propInfo != null && propInfo.get_CanRead()) { clrPropertyValue = propInfo.GetValue(workItem,nullindex);// get value PropertyValue = CLRInterop::getAnyTypeForObject(clrPropertyValue); target.AssignedTo = any2str(propertyValue); }
Hello, thanks for your response,
1 - I want to fetch AssignedTo field in order to see tasks that are not assigned to me, so i have cleaned the condition ([System.AssignedTo] = @me)
2 -there is no class WorkItemProxy in order to check the possibility to add methods i think it's in system layer
3- I have tried the approach with reflection:
3.1 when i execute this code :
</ propInfo= clrWorkItemType.GetProperty('AssignedTo');
if ( propInfo != null && propInfo.get_CanRead())
{
clrPropertyValue = propInfo.GetValue(workItem,nullindex);// get value
PropertyValue = CLRInterop::getAnyTypeForObject(clrPropertyValue);
target.AssignedTo = any2str(propertyValue);
}>
nothing happens
the value of the field Assigned is not retreived and no error is thrown
3.2 i tried to know if propInfo is empty so i changed the condition
</ propInfo= clrWorkItemType.GetProperty('AssignedTo');
if ( propInfo == null && propInfo.get_CanRead())
{
clrPropertyValue = propInfo.GetValue(workItem,nullindex);// get value
PropertyValue = CLRInterop::getAnyTypeForObject(clrPropertyValue);
target.AssignedTo = any2str(propertyValue);
}>
i had this error :
</SysVersionControlWorkItemProviderTFS objet not initialized.>
thank you so much.
What's the point of fetching AssignTo field if you have a condition to return only work items assigned to the current user ([System.AssignedTo] = @me)?
If you want to know whether WorkItemProxy class has get_AssignedTo() method, why don't you take a look? I can't do it for you (because I don't have AX 2012 environment).
If it doesn't have such a method, try the approach with reflection, which is used above for getting State and WorkItemType.
By the way, please use the </> button in the rich formatting view to paste source code; it makes it easier to read.
Thank you for your response,
1/ i have modified the query in order to return the field "Assigned To" as shown below :
/// <summary>
/// The <c>SysVersionControlWorkItemProviderTFS</c> class allows for TFS work items to be associated
/// with a Version Control System (VCS) check-in.
/// </summary>
// This is a framework class. Customizing this class may cause problems with future upgrades to the software.
public class SysVersionControlWorkItemProviderTFS implements SysVersionControlWorkItemProvider
{
Microsoft.Dynamics.AX.Framework.TeamFoundationServerFacade.WorkItemStoreProxy workItemStoreProxy;
Microsoft.Dynamics.AX.Framework.TeamFoundationServerFacade.WorkItemProxyCollection workItemsCache;
#define.AssignedToMeQuery("SELECT [System.Id], [System.Title], [System.State], [System.WorkItemType], [System.AssignedTo] FROM WorkItems WHERE [System.TeamProject] = @project AND [System.AssignedTo] = @me ORDER BY [System.Id]")
}
2/ My problem is how to get CurrentUser from WorkItem!!!!!, for example when i affect a string("CurrentUser") to Target.AssignedTo it appears in the form.
Question: WorkItem has methods to get title, id, i want to know if there is a way to add another methode get_assignedTo ??
code bellow :
private void insertWorkItemToTable(
SysVersionControlTmpWorkItems target,
Microsoft.Dynamics.AX.Framework.TeamFoundationServerFacade.WorkItemProxy workItem)
{
int id;
str title;
System.Type clrWorkItemType;
int instanceFlag = CLRInterop::getAnyTypeForObject(System.Reflection.BindingFlags::Instance);
int publicFlag = CLRInterop::getAnyTypeForObject(System.Reflection.BindingFlags::Public);
int combinedFlag = instanceFlag | publicFlag;
System.Reflection.BindingFlags propertyReflectFlags;
System.Reflection.PropertyInfo propInfo;
anytype propertyValue;
CLRObject clrPropertyValue;
System.Object nullIndex;
id = workItem.get_Id();
title = workItem.get_Title();
target.AssignedTo = "CurrentUser"; // the current user should be retreived from workItem
target.ID = id;
target.Title = title;
clrWorkItemType = workItem.GetType();
if (clrWorkItemType != null)
{
propertyReflectFlags = System.Reflection.BindingFlags::Default;
propertyReflectFlags = System.Enum::ToObject(propertyReflectFlags.GetType(), combinedFlag);
// BP Deviation Documented
nullIndex = new System.Object[0]();
propInfo = clrWorkItemType.GetProperty('State', propertyReflectFlags);
if (propInfo != null && propInfo.get_CanRead())
{
clrPropertyValue = propInfo.GetValue(workItem, nullIndex);
PropertyValue = CLRInterop::getAnyTypeForObject(clrPropertyValue);
target.State = any2str(propertyValue);
}
propInfo = clrWorkItemType.GetProperty('WorkItemType', propertyReflectFlags);
if (propInfo != null && propInfo.get_CanRead())
{
clrPropertyValue = propInfo.GetValue(workItem, nullIndex);
PropertyValue = CLRInterop::getAnyTypeForObject(clrPropertyValue);
target.Type = any2str(propertyValue);
}
}
target.insert();
if (workItemsCache.GetById(id) == null)
{
workItemsCache.Add(workItem);
}
}
SysVersionControlWorkItemProviderTFS class should contain a work item query in a macro. Do you see it? That's the first place you must change - you'll change the query to return an extra field.
Then you'll have to put the value (returned from a .NET library) to the table; unfortunately I don't remember the implementation and I don't have any AX 2012 environment on hand. If you think it's in insertWorkItemToTable() but you don't understands the code, please share it with us.
And by the way, don't forget to recompile the code using the macro (not just where the macro is defined).
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,280 Super User 2024 Season 2
Martin Dráb 230,235 Most Valuable Professional
nmaenpaa 101,156