7/4/2025 5:33:23 PM
|
|
slxdeveloper.com Community Forums |
|
|
|
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
Forum to discuss the use of the SalesLogix Web Platform, Client and Customer Portals, and the Application Architect (For version 7.2 and higher only). View the code of conduct for posting guidelines.
|
|
|
|
Problems with Auditing and Change Management for Account.Address
Posted: 04 Sep 09 10:43 AM
|
We've had some problems with the built in auditing, particularly involving extension entities on Ticket and the Address on Account, so we resorted to making our own auditing using the Change management stuff. Largely it works rather well. It will audit Account and AccountExtra but won't audit Account.Address. I can't just audit Address using the built in, because it will record every change to the Account history - what if it's a Contact Address?
Any ideas why it might work for Account and Account Extra, but not for Account.Address? Is it because Extra is an extension entity?
I'd be really grateful on your thoughts for the best way to audit address, this product is due to go live in the next couple of months and the auditing is a must, I'd rather not have to stick code on every single save!!
Here's the code we've got, obviously I've removed some sensitive stuff 
public static void AuditSaveStep( IAccount account) { //Audited fields (ac = account, ae = AccountExtra, ad = account.Address) //Enter Audited fields using PROPERTY NAME and friendly name in same order string[] acFields = {"Status", "Employees", "MainPhone"}; string[] acFriend = {"Account Status", "No. Of Employees", "Main Phone"};
string[] aeFields = {"StartDate"...}; string[] aeFriend = {"Trading Start Date"...};
string[] adFields = {"PostalCode", "Address1", "Address2", "Address3", "City", "Country", "County"}; string[] adFriend = {"Account Postal Code", "Address 1", "Address 2", "Address 3", "City", "Country", "County"};
string[] afFields = {"TURNOVER"}; string[] afFriend = {"Turnover"}; //Integers for loops... int i, j; //Get change states for Account, Account Extra and Address IChangedState accountState = account as IChangedState; IChangedState extraState = account.AccountExtra as IChangedState; IChangedState addressState = account.Address as IChangedState; IChangedState financeState = account.AccountFinance as IChangedState; //Check field changes first ArrayList acPropList = new ArrayList(); ArrayList aePropList = new ArrayList(); ArrayList adPropList = new ArrayList(); ArrayList afPropList = new ArrayList(); //Move through each of the audited fields to get change state for(i = 0; i < acFields.Length; i++) { acPropList.Add(accountState.GetChangedState().FindPropertyChange(acFields[i].ToString())); } for(i = 0; i < aeFields.Length; i++) { aePropList.Add(extraState.GetChangedState().FindPropertyChange(aeFields[i].ToString())); } for(i = 0; i < adFields.Length; i++) { adPropList.Add(addressState.GetChangedState().FindPropertyChange(adFields[i].ToString())); } for(i = 0; i < afFields.Length; i++) { afPropList.Add(financeState.GetChangedState().FindPropertyChange(afFields[i].ToString())); } //Record any changes to AccountHistory //Check Account fields first if (accountState != null) { //Move through each of the PropertyChange values for(j = 0; j < acFields.Length; j++) { PropertyChange tempChange = (PropertyChange)acPropList[j]; if(tempChange != null) { string oldValue = null; try { oldValue = tempChange.OldValue.ToString(); } catch { }
string newValue = null; try { newValue = tempChange.NewValue.ToString(); } catch { } if(string.IsNullOrEmpty(oldValue) && string.IsNullOrEmpty(newValue)) { //If changing from null to "" (or vice versa) no specific change so do nothing } else { //Remove time from timeless "date fields" (assumes that if they are timeless they have 00:00:05 at the end) if(newValue != null && newValue.Contains("00:00:05")) newValue = newValue.Substring(0, newValue.Length-9); if(oldValue != null && oldValue.Contains("00:00:05")) oldValue = oldValue.Substring(0, oldValue.Length-9); Sage.Entity.Interfaces.IAccountHistory newHist = Sage.Platform.EntityFactory.Create(); newHist.Account = account; newHist.FieldName = acFriend[j].ToString(); if(!string.IsNullOrEmpty(oldValue)) newHist.OldValue = oldValue; else newHist.OldValue = "N/A"; newHist.NewValue = newValue; newHist.Note = newHist.FieldName + " set to " + newValue + "."; newHist.Save(); } } } } //Now Check AccountExtra fields if (extraState != null) { //Move through each of the PropertyChange values for(j = 0; j < aeFields.Length; j++) { PropertyChange tempChange = (PropertyChange)aePropList[j]; if(tempChange != null) { string oldValue = null; try { oldValue = tempChange.OldValue.ToString(); } catch { }
string newValue = null; try { newValue = tempChange.NewValue.ToString(); } catch { } if(string.IsNullOrEmpty(oldValue) && string.IsNullOrEmpty(newValue)) { //If changing from null to "" (or vice versa) no specific change so do nothing } else { //Remove time from timeless "date fields" (assumes that if they are timeless they have 00:00:05 at the end) if(newValue != null && newValue.Contains("00:00:05")) newValue = newValue.Substring(0, newValue.Length-9); if(oldValue != null && oldValue.Contains("00:00:05")) oldValue = oldValue.Substring(0, oldValue.Length-9); Sage.Entity.Interfaces.IAccountHistory newHist = Sage.Platform.EntityFactory.Create(); newHist.Account = account; newHist.FieldName = aeFriend[j].ToString(); if(!string.IsNullOrEmpty(oldValue)) newHist.OldValue = oldValue; else newHist.OldValue = "N/A"; newHist.NewValue = newValue; newHist.Note = newHist.FieldName + " set to " + newValue + "."; newHist.Save(); } } } } //Now Check AccountExtra fields if (addressState != null) { //Move through each of the PropertyChange values for(j = 0; j < adFields.Length; j++) { PropertyChange tempChange = (PropertyChange)adPropList[j]; if(tempChange != null) { string oldValue = null; try { oldValue = tempChange.OldValue.ToString(); } catch { }
string newValue = null; try { newValue = tempChange.NewValue.ToString(); } catch { } if(string.IsNullOrEmpty(oldValue) && string.IsNullOrEmpty(newValue)) { //If changing from null to "" (or vice versa) no specific change so do nothing } else { //Remove time from timeless "date fields" (assumes that if they are timeless they have 00:00:05 at the end) if(newValue != null && newValue.Contains("00:00:05")) newValue = newValue.Substring(0, newValue.Length-9); if(oldValue != null && oldValue.Contains("00:00:05")) oldValue = oldValue.Substring(0, oldValue.Length-9); Sage.Entity.Interfaces.IAccountHistory newHist = Sage.Platform.EntityFactory.Create(); newHist.Account = account; newHist.FieldName = adFriend[j].ToString(); if(!string.IsNullOrEmpty(oldValue)) newHist.OldValue = oldValue; else newHist.OldValue = "N/A"; newHist.NewValue = newValue; newHist.Note = newHist.FieldName + " set to " + newValue + "."; newHist.Save(); } } } } if (financeState != null) { //Move through each of the PropertyChange values for(j = 0; j < afFields.Length; j++) { PropertyChange tempChange = (PropertyChange)afPropList[j]; if(tempChange != null) { string oldValue = null; try { oldValue = tempChange.OldValue.ToString(); } catch { }
string newValue = null; try { newValue = tempChange.NewValue.ToString(); } catch { } if(string.IsNullOrEmpty(oldValue) && string.IsNullOrEmpty(newValue)) { //If changing from null to "" (or vice versa) no specific change so do nothing } else { //Remove time from timeless "date fields" (assumes that if they are timeless they have 00:00:05 at the end) if(newValue != null && newValue.Contains("00:00:05")) newValue = newValue.Substring(0, newValue.Length-9); if(oldValue != null && oldValue.Contains("00:00:05")) oldValue = oldValue.Substring(0, oldValue.Length-9); Sage.Entity.Interfaces.IAccountHistory newHist = Sage.Platform.EntityFactory.Create(); newHist.Account = account; newHist.FieldName = afFriend[j].ToString(); if(!string.IsNullOrEmpty(oldValue)) newHist.OldValue = oldValue; else newHist.OldValue = "N/A"; newHist.NewValue = newValue; newHist.Note = newHist.FieldName + " set to " + newValue + "."; newHist.Save(); } } } } //Now that Auditing is done, save the account record account.Save(); }
|
|
|
|
You can
subscribe to receive a daily forum digest in your
user profile. View the site code
of conduct for posting guidelines.
Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
|
|
|
|
|
|
|
|