Validation on customer/vendor address

Hi all,

How can I validate customer/vendor address field while saving?

ie., I wan to customize customer/vendor data source to validate address while saving information.

Regards

Hi all,

Any comments???

Regards

Hi,

what exactly do you want to validate in the address and against what?

which AX version are you talking about?

Janis.

Hi Janis,

I am using AX 2009 and my requirment is customer/vendor information cannot save without Address(street name,city & country)

Regards

Then you need to write code to specifically check these fields on saving the record.

Well, in AX 2009 the easiest would be to add some extra code to the table Address, the method validateWrite().

Put this code somewhere at the end of the method, but BEFORE the “return ret” line.

if(DirPartyTable::isvendor(DirPartyTable::findRec(this.AddrRecId).PartyId) ||
DirPartyTable::isCustomer(DirPartyTable::findRec(this.AddrRecId).PartyId))
{
if (!this.Street ||
!this.City ||
!this.CountryRegionId)
return checkFailed(“What the… ? Do you call this a full address?”);
}

Change the error message of course [:D]

Enjoy.

Janis

Hi Janis

Thanks for your reply but this action will trigger only when you go to address tab and try to save something. User can save cutomer/vendor data without going to address tab.

For these purpose we can set the validation by making the fields mandatory.

But I am trying to put validation on CustTable/VendTable.Is there any way to do the same?

Regards

How? Do you really mean that user can save customer’s/vendor’s address in a standard AX 2009 without actually saving a single record in “Address” table?

You said that you want to check if the address entered for customers and vendors has been entered fully. My validation was meant to be set on a TABLE level, therefore it will be executed from whatever the place address is being entered. Whenever someone tries to create/modify an address for a CUSTOMER or a VENDOR, then the validation will definitely take place.

By making fields Street, City and Country as mandatory, you will set this type of limitation to each and every type of address in the whole AX (for the addresses which are stored in this “Address” table). I wouldn’t hurry by making all those fields mandatory unless you understand all consequences.

The half way house would be to check an entry exists in the address table on saving the record. The issue here is in validity and process. You can make fields and data mandatory, but it would not stop me setting the City as . and the street as . I just need to then pick a country from the lookup!

Thanks Adam & Janis for your reply…

My requirment is ‘very simple’ that user can’t save customer information without entering address like street,city or country.

@ Adam

Your comments are really appreciated .

If we are setting validation on address table then user can enter customer infoamtion without feeding any address value, means they will save all customer information excluding address. I want to restrict the user by they can’t save customer infoamation without address. User should enter atleast any of the address(like street,city or country) with other customer infoamtion.

Regards

Hi Ishak,

I don’t have AX 2009 in front and I don’t exactly remember how customer / vendor record is linked to address.

One option you may consider is to override ‘CanClose()’ method in CustTable and VendTable form and add this check there.

Only now after your last message I got that you want to check that at least one address has been saved per customer/vendor.

The thing is that in AX2009 the link between Address and Customer/Vendor is through RecId/TableId. As long as you haven’t saved the Customer/Vendor, you don’t have a valid recId which could be used for address table reference. Address table relies on a recId of the owner table. This means that you certainly can’t put a write validation on Customer/Vendor by requiring to enter an address. CustTable or VendTable record should be saved and only then Address can be assigned.

You can use the approach offered by Harish - you could throw an error (I would do ‘warning’) when user tries to close the CustTable/VendTable with an active record for which there is no entry in Address table.

Overwrite the canClose() method on CustTable and VendTable FORMS:

public boolean canClose()
{
boolean ret;
;

ret = super();

if (!Address)
{
ret = false;
warning(“Please enter at least one address for the customer!”);
}

return ret;
}