Search code examples
microsoft-dynamicsdynamics-ax-2009ax

Change PurchPrice on dynamics ax 2009 purchase requisition line


I want to insert a new product on a purchase requisition and edit the Purch Price but the field is read-only.

I try to unlock the field in the PurchReqTable form but it is already locked.

I try to find some run-time method that lock the field, but I was out of luck.

Any idea?


Solution

  • Have a look at the following method in the PurchReqTable Form:

    void setFieldAccess()
    {
        boolean allowEdit = purchReqFormMode == PurchReqFormMode::ShowAll ||
                            purchReqLine.LineType == PurchReqLineType::Category ||
                            isUserTaskOwner ||
                            isUserApprovalOwner;
        ;
    
        purchReqLine_ds.object(fieldnum(PurchReqLine,PriceUnit)).allowEdit(allowEdit);
        purchReqLine_ds.object(fieldnum(PurchReqLine,PurchUnit)).allowEdit(allowEdit);
        purchReqLine_ds.object(fieldnum(PurchReqLine,PurchPrice)).allowEdit(allowEdit);
        purchReqLine_ds.object(fieldnum(PurchReqLine,LineDisc)).allowEdit(allowEdit);
        purchReqLine_ds.object(fieldnum(PurchReqLine,LinePercent)).allowEdit(allowEdit);
        purchReqLine_ds.object(fieldnum(PurchReqLine,PurchMarkup)).allowEdit(allowEdit);
    
        purchReqLine_ds.object(fieldnum(PurchReqLine,CurrencyCode)).allowEdit(purchReqLine.RecId != 0);
        purchReqLine_ds.object(fieldnum(PurchReqLine,LineAmount)).allowEdit(!purchReqLine.isCatalogItem());
    }
    

    Notice how LineAmount is disabled if the current line contains a non-catalog item. Changing the settings on the datasource or the table will be overridden by this code at runtime. I hope this helps.