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.
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.
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.
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).
- 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.
Now lets add our code.
- Click on the “Edit Code Snippet hyperlink.
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:
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!
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.