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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

Approved Vendors for a specific ItemId

(0) ShareShare
ReportReport
Posted on by 30

Hello! I am new in Ax2012 and I am currently learning. I still don't know much code and I am trying my best to learn. I have to finish a task in my training. I created a new table and a new form where I have ItemId and Vendors. In that form I have to assign Vendors to a specific ItemId. So, if the ItemId has a AccountNum(Vendor) that means that ItemId can be sold only by that Vendor. If there is a ItemId without any AccountNum (Vendor) assigned, that means all vendors can sell that ItemId.
I have to create a code in EcoResProductDetailsExtended form in PurchLine DataSource in ItemId field. I created there a method validate. So when I choose a Vendor and I select the ItemId, based on the previous logic I have to see if the Vendor has a ItemId assigned. If it has, on the form you can add only that ItemId, but if you try to another ItemId which is not assigned for the vendor, then an errow will occure. If the Vendor has no specific ItemId assigned that means he can sell all other Items. 

I tried this code but it doesn't work the way I want, can somebody help me with the code please?

public boolean validate()
{
boolean ret;
boolean hasVendors;
HC_ApprovedVendors HCapproved;


ret = super();

select firstOnly HCapproved
where HCapproved.ItemId == PurchLine.ItemId
&& HCapproved.AccountNum == PurchTable.OrderAccount;
{
if (HC_ApprovedVendors::findItemId(HCapproved.ItemId))
{
if (HCapproved.RecId != 0)
{
HC_ApprovedVendors::findbyIndex(HCapproved.ItemId, HCapproved.AccountNum);
if (HCapproved.RecId !=0)
{
hasVendors = true;
}
}
}
}

if(hasVendors)
{
if(Hcapproved.ItemId != PurchLine.ItemId)
{
throw error ('The current vendor is not allowed for the purchase of this item');
}

// if (HCapproved.ItemId == PurchLine.ItemId
// && HCapproved.AccountNum != PurchTable.OrderAccount)
//{
//return ret;
//}
}

return ret;
}

I have the same question (0)
  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at
    RE: Approved Vendors for a specific ItemId

    Hi Hogan,

    There is existing functionality which takes care of the same functionality. Go to Released products form > Purchase tab (in action pane) > Approved vendors.

    pastedimage1646490378587v1.png

    Here you can setup the vendors from whom the item can be purchased.

    For the validation logic in purchase order lines, you can check PurchLine\pdsCheckApprovedVendorList method which is called from PurchLine\validateField method. If you are looking to duplicate the functionality, you can write similar logic in a PurchLine\validateWrite method , as you mentioned in the question.

  • HoganCosmin Profile Picture
    30 on at
    RE: Approved Vendors for a specific ItemId

    Hey, Thank you for help, but It is usefull for other situations, but I have to use in this task two find methods created in my table.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,047

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 885 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 592 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans