Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Fetching extra fields from TFS to check-in dialog

Posted on by Microsoft Employee

Good morning, I am working in the integration of ax 2012 R3 and TFS 2018. actually it works, my problem is how to custumize the Check in form in order to add some Tfs fields such as "AssignedTo" fields.  I could add the field in the form" SysVersionControlCheckIn"  and in the table, but i could not retreive information ( I mean the value of the field assigned To refering to the WorkItem) from TFS.  After searching the place where they populate values i found the class SysVersionControlWorkItemProviderTFS, exactly in the methode insertWorkItemToTable, but i didn't find how they populate values from tfs.  Can you help me please.  Thank you so much

Cliquez ou appuyez sur Entrée pour afficher sysVersioncontrolCheckIn.PNG dans l’aperçu de photosysVersioncontrolCheckIn.PNG

*This post is locked for comments

  • Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    RE: Fetching extra fields from TFS to check-in dialog

    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);
    }
  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: trouble with Microsoft Dynamics ax 2012 R3 with tfs 2018

    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.

  • Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    RE: trouble with Microsoft Dynamics ax 2012 R3 with tfs 2018

    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.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: trouble with Microsoft Dynamics ax 2012 R3 with tfs 2018

    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);

       }

    }

  • Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    RE: trouble with Microsoft Dynamics ax 2012 R3 with tfs 2018

    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.

  • Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    RE: trouble with Microsoft Dynamics ax 2012 R3 with tfs 2018

    And by the way, don't forget to recompile the code using the macro (not just where the macro is defined).

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans