Modifying an ATTACHMENT record when inserting an attachment into the SalesLogix web for a Sales Order

In the SalesLogix web client, you have the ability to attach a document to a specific sales order.  Attaching a document like this causes the file to be copied to the central attachment folder and also creates a database entry in the ATTACHMENT table in SalesLogix.


Prior to 7.5.3 there was an issue where the ATTACHMENT table record that was created incorrectly had the ACCOUNTID field populated with the SALESORDERID.  This caused an issue that the attachment was only visible at the Sales order level and not visible when looking at the Account’s attachment tab, as it should be.

In SalesLogix 7.5.3 this incorrect ACCOUNTID assignment has been fixed but there is still an issue that some might want to solve- causing an attachment added to a sales order to also be tied to a contact.


The SalesLogix sales order has three potential Contacts associated to it by default: The “Requested By”, “Billing Contact” and “Shipping Contact” for this reason I think Sage does not associate an attachment to a contact since different people might want to associate it differently.

Lets take a look at how we can potentially solve both the account link issue for pre 7.5.3 systems and also the contact linking issue.


Since the SalesLogix web client utilizes the SalesLogix entity model, we can take advantage of the entity events to do some extra stuff when a new attachment is inserted.


Lets walk through hooking into one of these events and adding our own code.


  • Open the Application Architect as Admin.
  • Under the Project Explorer (Cntrl+Alt+E to open) browse to the following location: VFS…Entity Model…Packages..>SalesLogix Application Entities…Attachment…Rules…Events.

SalesLogix Project Explorer- Attachment Entity Events

Since we want to manipulate the logic when a new attachment is added to the system we will be modifying the OnBeforeInsert event.

  • Double click on the OnBeforeInsert event.  The entity event definition dialog will open.

SalesLogix Attachment OnBeforeInsert dialog

You can see there is a Primary step defined.  To the right we can see this step is defined in the Sage assembly Sage.SalesLogix.BusinessRules.dll.  Since we don’t want to mess up the existing functionality, cannot modify that external assembly, and can have only one primary step per event, we don’t want to do anything here. 

  • Click on the Post Execute Steps tab.

SalesLogix Attachment OnBeforeInsert Post Execute dialog

The post execute steps area allows us to add as many steps here as we want. These steps will run in order, top to bottom, after completion of the Primary Step.

Lets go ahead and add our code. 

  • Click on the “Add” hyperlink on the Post Execute Steps tab.

A new dialog will popup asking us what kind of step we are adding. 

  • Choose C# Code Snippet. 
  • Once you select that go ahead and name the Snippet Name something meaningful (no spaces).

SalesLogix Attachment OnBeforeInsert Post Execute dialog 2

  • Click OK.

The dialog will close and we will be taken back to the Event definitions. We can now see our new event step listed.

 SalesLogix Attachment OnBeforeInsert Post Execute dialog 3

Now lets add our code. 

  • Click on the “Edit Code Snippet hyperlink.

SalesLogix Attachment OnBeforeInsert Code shell

SalesLogix will create the basic shell of our event step for us and adds a line of comment text showing where we want to place our code.

Now we can place in our code:

    Sage.Entity.Interfaces.ISalesOrder so = Sage.Platform.EntityFactory.GetById<Sage.Entity.Interfaces.ISalesOrder>(attachment.SalesOrderID);
        if (so.RequestedBy!=null) attachment.ContactId = so.RequestedBy.Id.ToString();
        if (so.Account!=null) attachment.AccountId = so.Account.Id.ToString();

 The finished code will look like this:

SalesLogix Attachment OnBeforeInsert Code complete

In this code, I am using the Requested By contact to populate the table.

Now all we need to do is to save our changes to both the step’s code file and the entity event.

After doing a rebuild and redeploying our web site, now when we add attachments to a sales order the records are correctly associated!

SalesLogix Attachment OnBeforeInsertcustom SQL results

Above, the first two rows in the database were prior to our fix,  This was on a 7.5.2 system so the AccountID is incorrectly associated as you can see.  The third row was a result of adding an attachment to the database after implementing our custom entity event.


Kris Halsrud

Kris Halsrud is a Senior Analyst / Developer for Customer FX Corporation.


  1. Kris,

    For the life of me I can not get this to work in 8.2.0. With my limited development skills I have isolated the issue to the fact that the attachment.SalesOrderID is Null when the method is called. I am not sure if they have changed the OnbeforeInsert rule. Any insight it would be appreciated.


    • Tim it may be that that event has changed to be in the onbeforeupdate rule. Maybe try moving that code into that event?

Submit a Comment

Your email address will not be published.

Subscribe To Our Newsletter

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

You have Successfully Subscribed!