Wednesday, February 23, 2011

SalesCreateQuotation - Always set an Address when creating a new Sales Quotation - Microsoft Dynamics AX 2009

I was faced with a very weird problem today at work. When a user goes to Sales Quotations and clicks the New button, he/she gets the SalesCreateQuotation form (Show below). In our implementation of this form, a contact is required. So, the user always has to choose a contact that is related to the business relationship that it is being quoted.

Now, the issue is that when users create a contact, they only set basic data such as email, and more often than not, the address fields are left blank.

Then, when a user chooses a contact from the Contact Drop Down List (look up), this form automatically was changing the Business Relationship address for the Contact address...but if the contact did not have any address setup, the "Delivery Address: fields in the SalesCreateQuotation form will be left blank. This of course created a problem.

To solve the problem I wrote a few lines of code that ensure that when selecting a contact that does not have an address, AX must show the original Business Relationship address. If both of this address are not present, then we present an error message saying that either of the record must have an address.

I implemented this code in the Modified() method of the editContactPersonName field in the SalesCreateQuotation form.

public boolean modified()
    boolean         ret;

    ret = super();

    //If !Contact Address replace the address fields with the current BusRelTable Address data
    if( !SalesQuotationTable.DeliveryStreet             ||
        !SalesQuotationTable.DeliveryZipCode            ||
        !SalesQuotationTable.DeliveryCity               ||
        !SalesQuotationTable.DeliveryCounty             ||
        !SalesQuotationTable.DeliveryState              ||
        custAccount = SalesQuotationTable_CustAccount.text();
            partyId = CustTable::find(custAccount, false).PartyId;
            busRelAccount = SalesQuotationTable_BusRelAccount.text();
            partyId = smmBusRelTable::find(busRelAccount).PartyId;

        busRelTable = SalesQuotationTable.GetBusRelTableInstance(partyId);
            if( busRelTable.Address             ||
                busRelTable.ZipCode             ||
                busRelTable.City                ||
                busRelTable.County              ||
                busRelTable.State               ||
                SalesQuotationTable.DeliveryStreet = busRelTable.Address;
                SalesQuotationTable.DeliveryZipCode = busRelTable.ZipCode;
                SalesQuotationTable.DeliveryCity = busRelTable.City;
                SalesQuotationTable.DeliveryCounty = busRelTable.County;
                SalesQuotationTable.DeliveryState = busRelTable.State;
                SalesQuotationTable.DeliveryCountryRegionId = busRelTable.CountryRegionId;
                Box::stop('@AIC588' + '@AIC589', '@AIC585', '@AIC585');
    //Earias - 2/14/2011
    // Check if the input exists in ContactPerson.Name
    if (ContactPerson::find(editContactPersonName.text()).Name)
        // Set the contactPersonName with the ContactPerson.Name
        contactPersonName = ContactPerson::find(editContactPersonName.text()).Name;
        // Set the contactPersonName with the input text.
        contactPersonName = editContactPersonName.text();

    if (!ContactPerson::findNameParty(salesQuotationTable.partyId(), contactPersonName))
        salesQuotationTable.ContactPersonId = ContactPerson::findOrCreateNameParty(salesQuotationTable.partyId(), editContactPersonName.text()).ContactPersonId;

    return ret;

The following is the SalesQuotationTable.GetBusRelTableInstance(partyId) method, which I implemented on the SalesQuotation Table.

smmBusRelTable GetBusRelTableInstance(DirPartyId partyId)
    smmBusRelTable busRelTable;
    select * from busRelTable where busRelTable.PartyId == partyId;
    return busRelTable;

No comments:

Post a Comment

Thank you for your thoughts. Your comment will appear in my blog shortly after review.

Have a great day!