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