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

Announcements

No record found.

News and Announcements icon
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

    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

    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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 617

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 461 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 298 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans