web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Creating Purchase Order from Purch Requisition from code (x++)

(0) ShareShare
ReportReport
Posted on by

Dear All,

We have some Purchase Requisitions which were approved but not generated into a Purchase Order. (The budget check is red).

 I want to create PO from PurchReqCreatePurchListPage form couldn't find the related PurchReq (I cleared all filters). The form is empty. I also clicked “View distributions" on the Financial Tab but it didn't solve the problem.

I decided to make it by calling "PurchReqCreatePurch_Action" menuItem from code side but I am getting error. Below is the code:

static void SYK_GeneratePurchOrderFromPurchReq()
{
   
    Args args = new Args();
    PurchReqLine                purchReqLine;
   
    select firstonly purchReqLine where purchReqLine.PurchReqTable == 5637168454 ;

    if(purchReqLine)
    {        
        args.record(purchReqLine);    
    }

    MenuFunction menuFunction = new MenuFunction(menuItemActionStr(PurchReqCreatePurch_Action(args)), MenuItemType::Action);
        
   }

I appreciate all your supports and suggestions for above issue, thanks.

Omer Ferhat Hancer

static void SYK_GeneratePurchOrderFromPurchReq()

{

Args args = new Args();

PurchReqLine purchReqLine;

select firstonly purchReqLine where purchReqLine.PurchReqTable == 5637168454 ;

if(purchReqLine)

{

args.record(purchReqLine);

}

MenuFunction menuFunction = new MenuFunction(menuItemActionStr(PurchReqCreatePurch_Action(args)), MenuItemType::Action);

}

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    It would help if you told us what the error was. But I assume since the PurchReq records are not visible on the form, they are not meant to be firmed into a PO because some data does not match.

  • Community Member Profile Picture
    on at

    When I compile the job, it underline the following code in red:

    "MenuFunction menuFunction = new MenuFunction(menuItemActionStr(PurchReqCreatePurch_Action(args)), MenuItemType::Action);"

    And just wrote: Error was found in Job SYK_GeneratePurchOrderFromPurchReq

  • Verified answer
    Community Member Profile Picture
    on at

    You can't declare a variable in the middle of a method.

    Move the declaration to the beginning

    MenuFunction menuFunction ;

    Args args = new Args();

    ....

    menuFunction = new MenuFunction(menuItemActionStr(PurchReqCreatePurch_Action(args)), MenuItemType::Action);

  • Community Member Profile Picture
    on at

    Thank you Jen, I was able to run the code.

    And yes you are right. It doesn't allow me to process thr Purch Req. I will try to find another way to generate Purchase Orders.

    FormDataSource object not initialised.

    Stack trace

    (S)\Classes\RequisitionReleaseStrategy\main - line 18

    (C)\Classes\xMenuFunction\run

    (C)\Classes\MenuFunction\run - line 85

    (C)\Jobs\SYK_GeneratePurchOrderFromPurchReq - line 14

  • Community Member Profile Picture
    on at

    Well you called the function from the menu item. Probably it expects to be called from a form which has a datasource and performs some action with the datasource.

    Calling a class from code mostly looks different (call construct, then parm() methods to set relevant data and then run)

    If you check the main() method of the class, you can see that it runs throught the data source and calls some method for all the selected records.

    I don't know the function and don't have time to analyze it, but by a quick look a the main method I would says you have to call this method for all the PurchReqs you want to firm:

    Map                             releaseStrategies = new Map(Types::Container, Types::Class);

    RequisitionReleaseStrategy::pushRequisitionLineToReleaseStartegy(purchReqLine, releaseStrategies);

    The method will probably add the purchReqLine to the releaseStrategies map.

    After you have done this you call:

    RequisitionReleaseStrategy::runReleaseStartegies(releaseStrategies, false);

    It will then probably create the POs for all the record in the map.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans