back to top

Getting the Add Edit Address popup dialog to work on the insert Account/Contact screen

Rich Eaton had asked a couple of times and I figured he was not the only one, so here it is!

Previously I had written about how to get around the shortcomings of the static edit address part of the address control by using the Add Edit Address Smartpart instead.

One thing that didn’t go into was how to do the same on the Insert Account/Contact screen. Both of these components are custom Smartparts,  so to make this work requires editing straight up ascx code.

 

Lets walk through it.  There are 2 things we need to do. 

  • Modify the insert Account/Contact Smartpart to launch our Add Edit Address quick form.
  • Modify the Added Edit Address Smartpart to work with the insert screen.

 The following was based on a 8.0 system.  Doing this on a 7.5 system shouldn’t be much different but the base code may vary slightly.

 

Editing the Insert Contact/Account SmartPart.

On the custom Contact SmartPart InsertContact.ascx perform the following steps:

Look for the end of the HTML markup.  This will be right above the line “<script runat=”server” type=”text/C#”>”.
Add the following components at the end of the HTML markup:

    <asp:Button ID=”btnEditContactAddress” runat=”server” OnClick=”btnEditContactAddress_Click” />
    <asp:Button ID=”btnEditAccountAddress” runat=”server” OnClick=”btnEditAccountAddress_Click” />

Search for the OnLoad event
Add the following code in within that method:

    //Editable Contact Address control CFX
        adrContactAddress.ReadOnly = true;
        adrContactAddress_lz.ForeColor = System.Drawing.Color.Blue;
        adrContactAddress_lz.Style[“text-decoration”] = “underline;”;
        adrContactAddress_lz.Text = “Address”;
        adrContactAddress_lz.ToolTip = “Click to Edit Address”;
        adrContactAddress_lz.Attributes.Add(“onclick”, “var btn= document.getElementById(‘” + btnEditContactAddress.ClientID + “‘); if(btn) btn.click();”);
        btnEditContactAddress.Style[“Display”] = “none”;

        //Editable Account Address control CFX
        adrAccountAddress.ReadOnly = true;
        adrAccountAddress_lz.ForeColor = System.Drawing.Color.Blue;
        adrAccountAddress_lz.Style[“text-decoration”] = “underline;”;
        adrAccountAddress_lz.Text = “Address”;
        adrAccountAddress_lz.ToolTip = “Click to Edit Address”;
        adrAccountAddress_lz.Attributes.Add(“onclick”, “var btn= document.getElementById(‘” + btnEditAccountAddress.ClientID + “‘); if(btn) btn.click();”);
        btnEditAccountAddress.Style[“Display”] = “none”;

Add 2 new methods into the code below the ending } of the OnLoad event:

    protected void btnEditAccountAddress_Click(object sender, EventArgs e)
    {
        Sage.Entity.Interfaces.IContact con = this.BindingSource.Current as Sage.Entity.Interfaces.IContact;

        if (DialogService != null)
        {
                DialogService.SetSpecs(200, 200, 440, 300, “FXAddEditAddress”, “”, true);
                DialogService.EntityType = typeof(Sage.Entity.Interfaces.IAddress);
                DialogService.DialogParameters.Clear();
                DialogService.DialogParameters.Add(“FXMode”, “InsertAccount”);                                
                DialogService.ShowDialog();
        }        
    }

    protected void btnEditContactAddress_Click(object sender, EventArgs e)
    {
        Sage.Entity.Interfaces.IContact con = this.BindingSource.Current as Sage.Entity.Interfaces.IContact;

        if (DialogService != null)
        {
                DialogService.SetSpecs(200, 200, 440, 300, “FXAddEditAddress”, “”, true);
                DialogService.EntityType = typeof(Sage.Entity.Interfaces.IAddress);
                DialogService.DialogParameters.Clear();
                DialogService.DialogParameters.Add(“FXMode”, “InsertContact”);
                DialogService.ShowDialog();
        }
    }

 

Remember you also need to add the AddEditAddress Smartpart as a defined Smartpart to the Insert Contact Account Page.  When you add the SmartPart, add it in the dialog workspace and ensure the the SmartPartId is “FXAddEditAddress” to match the code we added on the InsertContact.ascx Smartpart.

 

 

Modifying the AddEditAddress Smartpart

In order to get the Address quickform to now work with the Insert Contact/Account screen we need to add code on the load event of the quickform, as well as the save event.

On the custom Contact SmartPart AddEditAddress.ascx.cs perform the following steps:

On the method GetSmartPartInfo we want to change the title of the dialog based on how it was launched. 

We need to first comment out a standard line of code which assumes the parent entity has an ID.

Next we need to add an if else statement.  The standard code goes in the else and in the if we check to see if the dialog received an input parameter from our custom code added to the InsertContact.ascx.

Here is the full finished code:

public override ISmartPartInfo GetSmartPartInfo(Type smartPartInfoType)
    {
        ToolsSmartPartInfo tinfo = new ToolsSmartPartInfo();
        if (BindingSource != null)
        {
            if (BindingSource.Current != null)
            {
                IAddress address = (IAddress) BindingSource.Current;

                //txtEntityId.Value = _parentEntityReference.Id.ToString();
                if(_parentEntityReference.Id!=null) txtEntityId.Value = _parentEntityReference.Id.ToString(); //CFX

                object o = null;
                String FXType = string.Empty;
                DialogService.DialogParameters.TryGetValue(“FXMode”, out o);
                if (o != null)
                {
                    FXType = o.ToString();
                }
                if (!string.IsNullOrEmpty(FXType))
                {
                    IPersistentEntity persistentEntity = BindingSource.Current as IPersistentEntity;
                    Sage.Entity.Interfaces.IContact con = GetParentEntity() as Sage.Entity.Interfaces.IContact;
                    Mode.Value = “ADD”;
                    pklDecription.PickListValue = GetLocalResourceObject(“DefaultDescription”).ToString();
                   
                    if (FXType == “InsertAccount”)
                    {
                        tinfo.Title = GetLocalResourceObject(“DialogTitleAccountEdit”).ToString();
                        FXGetAddress(con.Account.Address);
                    }
                    else
                    {
                        tinfo.Title = GetLocalResourceObject(“DialogTitleContactEdit”).ToString();
                        FXGetAddress(con.Address);
                    }
                }
                else
                {
                    if (address.Id != null)
                    {
                        cbxIsPrimary.Enabled = (address.IsPrimary != true);
                        cbxIsShipping.Enabled = (address.IsMailing != true);
                        Mode.Value = “UPDATE”;
                    }
                    else
                    {
                        Mode.Value = “ADD”;
                        pklDecription.PickListValue = GetLocalResourceObject(“DefaultDescription”).ToString();
                    }

                    if (_parentEntityReference is IAccount)
                    {
                        tinfo.Title = Mode.Value == “ADD”
                                          ? GetLocalResourceObject(“DialogTitleAccountAdd”).ToString()
                                          : GetLocalResourceObject(“DialogTitleAccountEdit”).ToString();
                    }
                    if (_parentEntityReference is IContact)
                    {
                        tinfo.Title = Mode.Value == “ADD”
                                          ? GetLocalResourceObject(“DialogTitleContactAdd”).ToString()
                                          : GetLocalResourceObject(“DialogTitleContactEdit”).ToString();
                    }

                    if (!(_parentEntityReference is IAccount || _parentEntityReference is IContact))
                    {
                        tinfo.Title = Mode.Value == “ADD”
                                          ? GetLocalResourceObject(“DialogTitleAdd”).ToString()
                                          : GetLocalResourceObject(“DialogTitleEdit”).ToString();
                    }
                }
            }
        }

        foreach (Control c in AddressForm_LTools.Controls)
            tinfo.LeftTools.Add(c);
        foreach (Control c in AddressForm_CTools.Controls)
            tinfo.CenterTools.Add(c);
        foreach (Control c in AddressForm_RTools.Controls)
            tinfo.RightTools.Add(c);
        return tinfo;
    }

 

Next we add a couple of methods we can use in other areas.  One to get the current address data and set the controls of the user control (called from the GetSmartPart method).  The other sets the address based on the controls:

     protected void FXGetAddress(Sage.Entity.Interfaces.IAddress addr) //CFX
    {
        pklDecription.PickListValue = addr.Description;
        cbxPrimaryAddr.Checked = true;
        cbxIsPrimary.Checked = true;
        cbxIsShipping.Checked = true;
        cbxPrimaryAddr.Enabled = false;
        cbxIsPrimary.Enabled = false;
        cbxIsShipping.Enabled = false;
        pklAddressType.PickListValue = addr.Type;
        txtAddress1.Text = addr.Address1;
        txtAddress2.Text = addr.Address2;
        txtAddress3.Text = addr.Address3;
        pklCity.PickListValue = addr.City;
        pklState.PickListValue = addr.State;
        txtPostalCode.Text = addr.PostalCode;
        pklCounty.PickListValue = addr.County;
        pklCountry.PickListValue = addr.Country;
        txtSalutation.Text = addr.Salutation;
    }

    protected void FXSetAddress(Sage.Entity.Interfaces.IAddress addr) //CFX
    {
        addr.Description = pklDecription.PickListValue;
        addr.PrimaryAddress = cbxPrimaryAddr.Checked;
        addr.IsPrimary = cbxIsPrimary.Checked;
        addr.IsMailing = cbxIsShipping.Checked;
        addr.Type = pklAddressType.PickListValue;
        addr.Address1 = txtAddress1.Text;
        addr.Address2 = txtAddress2.Text;
        addr.Address3 = txtAddress3.Text;
        addr.City = pklCity.PickListValue;
        addr.State = pklState.PickListValue;
        addr.PostalCode = txtPostalCode.Text;
        addr.County = pklCounty.PickListValue;
        addr.Country = pklCountry.PickListValue;
        addr.Salutation = txtSalutation.Text;
    }

 

Next we need to use one of those new methods on the save click action.  This is the method btnSave_ClickAction.  Again, we are going to check to see if a dialog parameter was passed in inside an if statement.  If it was we use our new method to set the address entity from the controls of the dialog.  If no parameter exists, the else block does the standard save action.  Here is the complete code:

    protected void btnSave_ClickAction(object sender, EventArgs e)
    {
        //CFX
        object o = null;
        String FXType = string.Empty;
        DialogService.DialogParameters.TryGetValue(“FXMode”, out o);
        if (o != null)
        {
            FXType = o.ToString();
        }
        if (!string.IsNullOrEmpty(FXType))
        {
            IPersistentEntity persistentEntity = BindingSource.Current as IPersistentEntity;
            Sage.Entity.Interfaces.IContact con = GetParentEntity() as Sage.Entity.Interfaces.IContact;

            if (FXType == “InsertAccount”)
            {
                FXSetAddress(con.Account.Address);
                if (!(con.Address.PrimaryAddress.HasValue?con.Address.PrimaryAddress.Value:false)) FXSetAddress(con.Address);
            }
            else
            {
                FXSetAddress(con.Address);
                if (!(con.Account.Address.PrimaryAddress.HasValue?con.Account.Address.PrimaryAddress.Value:false)) FXSetAddress(con.Account.Address);
            }
        }
        else //END CFX, normal code below
        {
            IPersistentEntity persistentEntity = BindingSource.Current as IPersistentEntity;
           
            _parentEntity = GetParentEntity() as IPersistentEntity;
            _parentEntityReference = _parentEntity as IComponentReference;

            if (persistentEntity != null)
            {
                bool hasContactMatches = false;
                IAddress address = (IAddress)BindingSource.Current;
                if (Mode.Value == “ADD”)
                    persistentEntity.Save();
                if (Mode.Value == “UPDATE”)
                {
                    IContact contact = _parentEntityReference as IContact;
                    IAccount account = _parentEntityReference as IAccount;

                    bool hasSalesOrderMatches = (Helpers.HasMatchingSalesOrderAddresses(_parentEntityReference));
                    if (contact != null)
                        hasContactMatches = contact.HasAddressChanges();
                    else if (account != null)
                        hasContactMatches = account.HasAddressChanges();
                    if ((hasContactMatches || hasSalesOrderMatches) && DialogService != null)
                    {
                        UpdateAddressOptionManager addressOptions = new UpdateAddressOptionManager();
                        addressOptions.HasContactAddressChanges = hasContactMatches;
                        addressOptions.OldAddressValues = contact != null
                                                                ? Sage.SalesLogix.Contact.Rules.getOriginalAddressValues(
                                                                    contact)
                                                                : Sage.SalesLogix.Account.Rules.getOriginalAddressValues(
                                                                    account);
                        addressOptions.HasSalesOrderAddressChanges = hasSalesOrderMatches;
                        addressOptions.ParentEntityReference = _parentEntityReference;
                        addressOptions.IsPrimaryAddress = (address.IsPrimary ?? false);

                        DialogService.SetSpecs(200, 200, 200, 450,
                                                contact != null ? “UpdateContactOptions” : “UpdateAccountOptions”, “”, true);
                        DialogService.EntityType = typeof(IAddress);
                        DialogService.EntityID = address.Id.ToString();
                        DialogService.DialogParameters.Add(“UpdateAddressOptionManager”, addressOptions);
                        DialogService.ShowDialog();
                    }
                    persistentEntity.Save();
                }
            }
            UpdateFlags();
        }
        btnSave_ClickActionBRC(sender, e);
    }

 

Contact Customer FX for your CRM project
We let our expertise speak for itself - let us know how our all-star team can help on your CRM project
About the Author
Kris Halsrud
Kris Halsrud
Kris Halsrud is a Senior Analyst / Developer for Customer FX Corporation.

5 COMMENTS

  1. I’m trying to do this in an 8.3 (update 4) environment. I can’t get the 2 on click methods in the first part to work ( Add 2 new methods into the code below the ending } of the OnLoad event:). It throws an error saying expecting }. If I add the } it says it wants, all hell breaks loose.

    • Are you sure you are putting that in the right spot? It should be fine as long as the code you are adding is after the closing } of the OnLoad method.

  2. Here is the on load.
    protected override void OnLoad(EventArgs e)
    {
    //Editable Contact Address control CFX
    adrContactAddress.ReadOnly = true;
    adrContactAddress_lz.ForeColor = System.Drawing.Color.Blue;
    adrContactAddress_lz.Style[“text-decoration”] = “underline;”;
    adrContactAddress_lz.Text = “Address”;
    adrContactAddress_lz.ToolTip = “Click to Edit Address”;
    adrContactAddress_lz.Attributes.Add(“onclick”, “var btn= document.getElementById(‘” + btnEditContactAddress.ClientID + “‘); if(btn) btn.click();”);
    btnEditContactAddress.Style[“Display”] = “none”;

    //Editable Account Address control CFX
    adrAccountAddress.ReadOnly = true;
    adrAccountAddress_lz.ForeColor = System.Drawing.Color.Blue;
    adrAccountAddress_lz.Style[“text-decoration”] = “underline;”;
    adrAccountAddress_lz.Text = “Address”;
    adrAccountAddress_lz.ToolTip = “Click to Edit Address”;
    adrAccountAddress_lz.Attributes.Add(“onclick”, “var btn= document.getElementById(‘” + btnEditAccountAddress.ClientID + “‘); if(btn) btn.click();”);
    btnEditAccountAddress.Style[“Display”] = “none”;

    base.OnLoad(e);
    ClientBindingMgr.RegisterBoundControl(lueUseExistingAccount);
    ClientBindingMgr.RegisterSaveButton(cmdSave);
    ClientBindingMgr.RegisterSaveButton(cmdSaveClear);
    ClientBindingMgr.RegisterSaveButton(cmdSaveNew);
    LoadView();

    protected void btnEditAccountAddress_Click(object sender, EventArgs e)
    {
    Sage.Entity.Interfaces.IContact con = this.BindingSource.Current as Sage.Entity.Interfaces.IContact;

    if (DialogService != null)
    {
    DialogService.SetSpecs(200, 200, 440, 300, “FXAddEditAddress”, “”, true);
    DialogService.EntityType = typeof(Sage.Entity.Interfaces.IAddress);
    DialogService.DialogParameters.Clear();
    DialogService.DialogParameters.Add(“FXMode”, “InsertAccount”);
    DialogService.ShowDialog();
    }
    }

    protected void btnEditContactAddress_Click(object sender, EventArgs e)
    {
    Sage.Entity.Interfaces.IContact con = this.BindingSource.Current as Sage.Entity.Interfaces.IContact;

    if (DialogService != null)
    {
    DialogService.SetSpecs(200, 200, 440, 300, “FXAddEditAddress”, “”, true);
    DialogService.EntityType = typeof(Sage.Entity.Interfaces.IAddress);
    DialogService.DialogParameters.Clear();
    DialogService.DialogParameters.Add(“FXMode”, “InsertContact”);
    DialogService.ShowDialog();
    }
    }
    }

    That’s the override, I tried putting it in the private void LoadView() with the same results.

    I’m sure you can tell that I’m pretty new to this. We just started using web.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Infor CRM Sync for Exchange: Action Required by August 31, 2026

Using Infor CRM Sync for Exchange with Microsoft 365? Your Exchange administrator must update tenant settings by August 31, 2026 to prevent sync disruption.

[Webinar] What’s Coming Next for Infor CRM SLX and Why v10 Matters

See what’s coming next for Infor CRM SLX, including new marketing workflows, automation improvements, and reasons to consider upgrading to v10.

Disable Caching in Infor CRM SLX Web Client

In the rare case caching is causing issues in the Infor CRM SLX web client, it is possible to disable specific types of caching by making edits using Application Architect, and then deploying.

Exploring AI Options for Infor CRM v10

I've started taking a closer look at the AI capabilities built into Infor CRM v10. Over the next several posts, I'll share what I learn. From the built-in features and supported AI providers to implementation considerations, costs, and practical use cases.

Infor CRM SLX 10.0: Delegate Ownership Changes for “Everyone” Records

Learn how the new EveryoneOwnerAssignment secured action in Infor CRM SLX 10.0 allows designated users to change ownership of Everyone-owned records without requiring Administrator access.

Related Articles

Infor CRM Sync for Exchange: Action Required by August 31, 2026

Using Infor CRM Sync for Exchange with Microsoft 365? Your Exchange administrator must update tenant settings by August 31, 2026 to prevent sync disruption.

[Webinar] What’s Coming Next for Infor CRM SLX and Why v10 Matters

See what’s coming next for Infor CRM SLX, including new marketing workflows, automation improvements, and reasons to consider upgrading to v10.

Disable Caching in Infor CRM SLX Web Client

In the rare case caching is causing issues in the Infor CRM SLX web client, it is possible to disable specific types of caching by making edits using Application Architect, and then deploying.

Exploring AI Options for Infor CRM v10

I've started taking a closer look at the AI capabilities built into Infor CRM v10. Over the next several posts, I'll share what I learn. From the built-in features and supported AI providers to implementation considerations, costs, and practical use cases.

Related Videos