Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

X++ Get Production Unit of a Production Order

Posted on by 1,204

Hi,

I'd like to get the Production Unit of a Production Order from Applicable resources form as in screenshot below:

2844.produnit.png

The form path is Production Order -> Production route -> Applicable resources.

The query in Applicable resources form starts with WrkCtrTable so I figured I need to join WrkCtrTable from ProdRoute but I couldn't find the correct relation between these two tables anywhere.

That's weird. I don't see any other way to get to the Production Unit. 

Has anyone ever done this? 

Thank You.

*This post is locked for comments

  • Verified answer
    HAIRUL HAZRI Profile Picture
    HAIRUL HAZRI 1,204 on at
    RE: X++ Get Production Unit of a Production Order

    I discovered that the following query works. It's the continuation from the Resource requirement job from the link in my previous comment. For now, this solves my problem.

    static void ProdRoute_Resources(Args _args)
    {
        ProdRoute                       prodRoute;
        RecId                           activityRequirementSetRecId;
        WrkCtrActivityRequirementEdit   requirementEdit;
        ProdId                          prodId = "GF-BO-000100";
        WrkCtrActivityRequirementType   relationShipType;
        WrkCtrActivityRequirement       wrkCtrActivityRequirement;
        WrkCtrCapability                wrkCtrCapability;
        WrkCtrCapabilityResource        wrkCtrCapabilityResource;
        WrkCtrTableIndividualView       wrkCtrTableIndividualView;
    
        while select prodRoute
            where prodRoute.ProdId == prodId
        {
            activityRequirementSetRecId = prodRoute.activityRequirementSet().RecId;
    
            select WrkCtrActivityRequirement
                where WrkCtrActivityRequirement.ActivityRequirementSet == activityRequirementSetRecId;
            requirementEdit =  WrkCtrActivityRequirement.requirementEdit();
            relationShipType = WrkCtrActivityRequirement.RelationshipType;
    
            info(strFmt("%1, %2",relationShipType, requirementEdit));
    
            
            while select wrkCtrCapability where wrkCtrCapability.Name == requirementEdit
                join wrkCtrCapabilityResource where wrkCtrCapabilityResource.Capability == wrkCtrCapability.RecId
                join WrkCtrId,ProdUnitId from  wrkCtrTableIndividualView
                group by wrkCtrTableIndividualView.ProdUnitId
                where wrkCtrTableIndividualView.WrkCtrId == wrkCtrCapabilityResource.WrkCtrId
            {
                info(strFmt("%1", wrkCtrTableIndividualView.ProdUnitId));
            }
        }
    }


    Thank you for pointing out that WrkCtrApplicableResourceQuery class. I can use it to double confirm my findings. Cheers :)

  • Suggested answer
    Rustem Galiamov Profile Picture
    Rustem Galiamov 8,072 on at
    RE: X++ Get Production Unit of a Production Order

    You can set breakpoint to the WrkCtrApplicableResourceQuery class query() method and you will see how query will be generated when you open Applicable resources form from Production Route form.

  • HAIRUL HAZRI Profile Picture
    HAIRUL HAZRI 1,204 on at
    RE: X++ Get Production Unit of a Production Order

    Okay that's new. Can you elaborate more? 

    So I was referring this link to get the Resource requirements. But then still, I don't see any way I can relate the record to the Applicable resources.

    How exactly does the Applicable resources depend on Resource requirements?

  • Verified answer
    Rustem Galiamov Profile Picture
    Rustem Galiamov 8,072 on at
    RE: X++ Get Production Unit of a Production Order

    Applicable resources depends from Resource requirements (Resource requirements tab in Production Route form).

  • HAIRUL HAZRI Profile Picture
    HAIRUL HAZRI 1,204 on at
    RE: X++ Get Production Unit of a Production Order

    Hmm now that makes it even more weird. How can the form possibly get the Applicable resources when it has no relation with ProdRoute in the first place?

    Is there any workaround for this? I just want to get the Production unit(s) given a Production Order number (ProdId).

    I don't see any other way I can do it.

  • Rustem Galiamov Profile Picture
    Rustem Galiamov 8,072 on at
    RE: X++ Get Production Unit of a Production Order

    I think there is no direct link between ProdRoute and WrkCtrTable.

    This is the generated query when you open the form from ProdRoute:

    SELECT * FROM WrkCtrTable(WrkCtrTable_1) WHERE ((IsIndividualResource = 1)) 
    EXISTS JOIN * FROM WrkCtrResourceGroupResource(WrkCtrResourceGroupResource_1)         
        WHERE WrkCtrTable.WrkCtrId = WrkCtrResourceGroupResource.WrkCtrId 
    EXISTS JOIN * FROM WrkCtrResourceGroup(WrkCtrResourceGroup_1) 
        WHERE WrkCtrResourceGroupResource.ResourceGroup = WrkCtrResourceGroup.RecId 
          AND ((SiteId = N'Общий')) AND ((IsWorkCell = 0)) 
    JOIN * FROM WrkCtrTableIndividualView(WrkCtrTableIndividualView_1) 
        ON WrkCtrTable.WrkCtrId = WrkCtrTableIndividualView.WrkCtrId 
        AND ((ValidFrom<={ts '2018-10-02 00:00:00.000'})) AND ((ValidTo>={ts '2018-10-02 00:00:00.000'}))
  • HAIRUL HAZRI Profile Picture
    HAIRUL HAZRI 1,204 on at
    RE: X++ Get Production Unit of a Production Order

    You're right I can see that. But then how can I join from ProdRoute to WrkCtrTable and WrkCtrTableIndividualView?

    Do you know any workaround?

  • Suggested answer
    Rustem Galiamov Profile Picture
    Rustem Galiamov 8,072 on at
    RE: X++ Get Production Unit of a Production Order

    There is no relation between WrkCtrActivityRequirementSet and WrkCtrTable.

    When you open Applicable resources form from Production Route form the init() method of WrkCtrActivityRequirementSet DS adding a link between caller record and WrkCtrActivityRequirementSet in Applicable resources form:

    Screen-Shot-2018_2D00_10_2D00_02-at-13.17.01.png

  • HAIRUL HAZRI Profile Picture
    HAIRUL HAZRI 1,204 on at
    RE: X++ Get Production Unit of a Production Order

    Hi Rustem Galiamov,

    Yes, I'm aware of that. My problem is I couldn't see how can I join WrkCtrTable from ProdRoute even though the Applicable resources form is called directly from Production route form.

    From Production Route form, I did find following relations:

    ProdRoute -> WrkCtrProdRouteActivity -> WrkCtrActivity -> WrkCtrActivityRequirementSet

    But from WrkCtrActivityRequirementSet I didn't find the relation to WrkCtrTable.

    Any idea?

    Best Regards.

  • Suggested answer
    Rustem Galiamov Profile Picture
    Rustem Galiamov 8,072 on at
    RE: X++ Get Production Unit of a Production Order

    Hi HAIRUL HAZRI!

    The Production Unit field it's a field from WrkCtrTableIndividualView view. This view joined to WrkCtrTable.

    Screen-Shot-2018_2D00_10_2D00_02-at-11.29.53.png

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans