Contact Person in AX2009

Can someone please tell me how to get the Veddor Contact Person name in AX2009?

I have a vendor setup in VendTable, from what said in documentation, I can get the contact person from the contactpersonid, but it does not work, I tried the Dirpartytable and don’t know what was the link to get the correct contact name.

Thanks in advance.

Hi,

I had a look at the VendTable form, the contact person is populated by an edit method, vendTable.editContactPersonName(), If you look at this method:

return this.CustVendTable::editContactPersonName(_set, _name);

not so clear, but if you have a look at CustVendTable map’s method editContactPersonName, there’s all you need to have the contact name

Let me know if you need more explanations

Regards,

Thomas

Thanks Thomas,

I think I still can’t get the relationship right, I checked the dirparty table, vendtable but cannot link them together using the name and partyid, I tried the CustVendTable map’s method editContactPersonName, but I don’t think I understand the logic, can you please explain? Thanks

Tania

Hi Tania,

VendTable vendTable;
;
select vendTable
where vendTable.AccountNum == ‘xx’;
info(vendTable.editContactPersonName(false,’’));

This is taken from CustVendTable.editContactPersonName():

if (this.ContactPersonId)
{
	_name = ContactPerson::find(this.ContactPersonId).Name;
}
else
{
	switch (this.TableId)
	{
		case tablenum(CustTable):
			whereFieldId = fieldnum(ContactPerson,CustAccount);
			break;
		case tablenum(VendTable):
			whereFieldId = fieldnum(ContactPerson,VendAccount);
			break;
	}
	select contactPerson
		where contactPerson.(whereFieldId) == this.AccountNum
		   && contactPerson.Name like _name;

	if (contactPerson)
	{
		this.ContactPersonId = contactPerson.ContactPersonId;
		_name = contactPerson.Name;
	}
}

It first tries to find a contact person by name. If it doesn’t succeed, it looks for a contact person with the given VendAccount and it considers _name as a search pattern (e.g. “A*”) instead of an exact name.

Hi Tania,

Martin did a nice explanation and Kuppusamy’s sample code works, I have nothing more to say

regards,

Thomas

Hi all,

thanks very much for all your answer, the fact the I am new to AX and only know the SQL side of things does not help.

I need to pick up directly from the SQL table column values, but from what I can find, it seems very complicated, at least I cannot find a direct link between the “accountnum” in the Vendtable and the DirPartyTable which I guess is where the contact person stores

Do you have any idea which table the contact person comes from and how to join this from the VendTable?

Thanks heaps

Contact persons are in ContactPerson table, as you can see above.

This code:

select contactPerson
    where contactPerson.(whereFieldId) == this.AccountNum
    && contactPerson.Name like _name;

is, after expansion of whereFieldId, the same as:

select contactPerson
    where contactPerson.VendAccount == this.AccountNum
    && contactPerson.Name like _name;

Nothing difficult.

Nevertheless direct access to database is not recommended - you would have to duplicate all AX logic, AX security (including record-level security) wouldn’t be applied and so on. You have things like AIF for integration with other applications.