Hi,
could someone please help me to solve the following problem, which i´ve at the moment: First of all i create a web service for the purpose of updating and then merging duplicates of given account per SData. Updating works fine. Merging duplicates of given account causes unknowable exception and frustrated me a lot I try to call the custom business rule like this:
bool retVal = false; string OpName = "MergeAccounts"; string DuplicateIds = string.Join(",", SubsequentDuplicateIds);
try { SDataServiceOperationRequest sreq = new SDataServiceOperationRequest(SDataServant) { ResourceKind = SDataResourceKind.Accounts, OperationName = OpName };
sreq.Entry = new AtomEntry();
sreq.Entry.SetSDataPayload( new SDataPayload { ResourceName = "Account" + sreq.OperationName, Namespace = "http://schemas.sage.com/dynamic/2007", Values = { {"request",new SDataPayload { Values = { {"AccountID", headerAccountId}, {"EntityIDs", DuplicateIds} } } } } } );
AtomEntry result = sreq.Create(); var res = (SDataPayload)result.GetSDataPayload().Values["response"]; retVal = res.Values["Result"].ToString().ToLower().Equals("true"); }
The custom business rule:
using (ISession session = new Sage.Platform.Orm.SessionScopeWrapper(true)) { try { string[] DuplicateIDs = EntityIDs.Split(new char[] { ',' }); Type mergeType = typeof(Sage.Entity.Interfaces.IAccount); //bool success = false;
if (DuplicateIDs != null) { foreach (string sourceEntityId in DuplicateIDs) { MergeArguments SessionMergeArguments = new MergeArguments(); SessionMergeArguments.SourceEntityId = sourceEntityId; SessionMergeArguments.SourceEntityType = mergeType; SessionMergeArguments.TargetEntityId = AccountID; SessionMergeArguments.TargetEntityType = mergeType; SessionMergeArguments.MergeProviderType = mergeType;
MergeProvider sessionMergeProvider = (MergeProvider)MergeArguments.GetMergeProvider(SessionMergeArguments); sessionMergeProvider.RecordOverwrite = MergeOverwrite.targetWins;
IAccount myaccount = (IAccount)SessionMergeArguments.MergeProvider.Target.EntityData;
if (myaccount.MergeAccount(SessionMergeArguments.MergeProvider)) { string entityId = SessionMergeArguments.MergeProvider.Source.EntityId; IPersistentEntity duplicateAccount = Sage.Platform.EntityFactory.GetById(mergeType, entityId) as IPersistentEntity; duplicateAccount.Delete();
result = "Success"; } } } } catch (ApplicationException e) { result = e.Message; } }
The problem will be caused of (MergeProvider)MergeArguments.GetMergeProvider(SessionMergeArguments) - the system gives the Result "Error getting merge configuration." back. I dont know why and dont know how to help me now. Testing the method MergeAccounts(IAccount account, string AccountID, string EntityIDs, string out result) in SLX-Context does not cause problem, i.e. creating a button binding to the (custom) business rule on click action.
It would be very nice when someone of you could tell me, what i have implemented wrongly. Thanks a lot for your help in adv!
|