Skip to main content

Notifications

Announcements

No record found.

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;
}

  • 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.

  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,421 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.

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,349 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,029 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans