Showing posts with label smmActivities. Show all posts
Showing posts with label smmActivities. Show all posts

Thursday, March 3, 2011

Filter the Activity Form contact to only existing records on a Business Relationship by creating a Lookup Dynamically- AX 2009

Today a user came to me and asked me if I would be able to show only the contacts related to a Business Relationship when choosing a contact in the Activity form.


The following is the form:



 The original setup would show all the contacts available table wise. This was a problem for the users as it will take a lot of time for them to find the right contact.

Set the Business Relationship Account in the Activities Form

Yesterday I had a requirement that said to pre-populate the Business Relationship Account in the Activities Form field Business Account upon creation of a new activity.

To do this I modified the InitValue() method within the smmActivities Data Source:

Forms > smmActivities > DataSources > smmActivities > Methods > InitValue


To do it I had to make sure that the element that was calling the form was the smmBusRelTable, then I assigned the element record to my smmBusRelTable variable. Finally, upon checking the validity of the record, I assigned the busRelTable.BusRelAccount to the busRelAccount in the smmActivities table.

The code is as follows:


THE FOLLOWING CODE GOES INTO THE FORM INIT METHOD
if (element.args().dataset() == tablenum(smmBusRelTable))
    {
        busRelTable = element.args().record();
        //businessRelationRange.value(smmBusRelTable.BusRelAccount);
    }

This Goes in the smmActivities data source initvalue().
    if(busRelTable.BusRelAccount)
    {
        smmActivities.smmBusRelAccount = busRelTable.BusRelAccount;
    }