Adding an Address lookup to the Account Assets add edit view in Infor CRM8.1 (Formerly SalesLogix)

In today’s post, I’ll be outlining a procedure to add an Address field to an Account Asset (Product) record.

Goal/Description:

To add an address field to Account assets (products) that allows a user to define an existing Account Address for an Asset (AccountProduct) record.  The addressed will be stored in the AccountProduct.Userfield1 field.

  1. Detail/Steps:
    1. Make Userfield1 available for Account Products
      1. In Application Architect, right click the AccountProduct entity and select UpdateProperties. If it is not already selected, select the Userfield1 field to include the property on the entity. If Userfield1 is already selected, skip to b.
      2. Double click the AccountProduct entity to get the Properties list. Find the Userfield 1 property in the list and make sure the “Include” checkbox is checked.
      3. Save changes to the entity, and build interfaces.
    2. Add a new Lookup control to the AddEditAccountProduct quickform.
      1. On wizard set the following:
        1. What information will you be looking up?
          1. Address
        2. Which property will receive the result of this lookup?
          1. Userfield1
        3. Select how the lookup control will display
          1. Dialog
        4. Allow lookup selection to be cleared
          1. Check if you want users to be able to clear and address for the asset.
        5. Select properties that you want to see in the result grid.
          1. Pick which ever properties you want in the lookup. I’d suggest Address1, city, state, postalcode. The lookup will default to search the first item in the list.
        6. Click OK.
      2. Verify/Set additional properties:
        1. Caption:
          1. Whatever you would like. “Address” would be appropriate.
        2. Initialize lookup
          1. True – This will fill the lookup upon opening (you don’t have to hit “Search”)
        3. Return Primary Key
          1. True (Should be this by default. This will cause the addressid to be stored)
        4. Lookup Binding Mode
          1. “String” (Should be this by default)
        5. Lookup Properties
          1. You can change the order of the fields contained in the lookup. The search on the lookup will default to the first item in the list. There has to be one lookup field, but you can set the ExcludeFromFilter property = False for all other Fields in case the field you want to use is not the first in the list.
        6. Seed Property
          1. “EntityId” (Case sensitive. This will allow us to restrict the lookup result to the AccountID.)
        7. OnChangeAction
          1. Add a C# Snippet action with no code. This will force a post-back.
      3. Set Onload Event for Form
        1. Create a new C# Snippet Action item
          1. On Repaint Event = True
        2. CSharp Code (See below)

CSharp Code:

The code we add is needed to do the following:

  • Set the Seed value of the control, to restrict the addresses returned by accountid
  • Set The display of the Address control to show whichever field you want to see on the form. (This can be skipped, but the control will then show the String Expression defined on the Saleslogix Extended tab of the Entity page. By default, this is the Address Description.

Code Sample:

//Create a entity object for AccountProduct
Sage.Entity.Interfaces.IAccountProduct acp = this.BindingSource.Current as Sage.Entity.Interfaces.IAccountProduct;
if (acp != null && acp.Account != null) //Check to see if objects are null, otherwise we'll get a null reference exception error when adding a new asset.
{
    //Set seed value to accountid
    lueAddress.SeedValue = acp.Account.Id.ToString();
}

//If you are ok displaying the value from the String Expression defined under the entities SalesLogix extended tab, the rest of this code can be skipped.

//Create empty variable to hold display value
string addrValue = string.Empty;
//Check to see if the address lookup is blank.
if (lueAddress.LookupResultValue != null)
{
    //Get the addressID for the address currenly defined for the asset (if any).
    string sAddressID = lueAddress.LookupResultValue.ToString();

    //Use the addressid to create another entity object for the address entity.
    Sage.Entity.Interfaces.IAddress addr = Sage.Platform.EntityFactory.GetById<Sage.Entity.Interfaces.IAddress>(sAddressID) as Sage.Entity.Interfaces.IAddress;
    //Set the variable to disired display field (Address1 in this example).
    if (addr != null) { addrValue = addr.Address1; }
}

//The lookup control is a composite control, so we need to loop through the base control types to find the correct property on which to set the display value.
foreach (Control c in lueAddress.Controls)
{      
    if (c.ClientID.EndsWith("_LookupText"))
    {
        //Set the display to show the field defined above (currently Address1)
        ((TextBox)c).Text = addrValue;           
    }
}

Once the Changes have been completed, save the quickform, Build the Web platform, and re-deploy the Web portal.

ABOUT THE AUTHOR

Jason Buss

Jason is a senior application developer with Customer FX.

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Join our mailing list to receive the latest Infor CRM (Saleslogix) news and product updates!

You have Successfully Subscribed!