2012-07-30 48 views
2

我創建的Microsoft Dynamics插件CRM 4,將根據另一查找字段的值更改帳戶實體的所有者更改帳戶的所有者對CRM 4.0。現在我已經設法獲取將充當帳戶「所有者」的用戶的GUID。到現在爲止還挺好。 我嘗試更改所有者時出現問題。我正在嘗試使用AssignRequest,但它不起作用。當我嘗試執行請求時,我在C#調試器上得到一個SoapException,並且webservice輸出一個對話框: 「請求的記錄未找到或者您沒有足夠的權限查看它」嘗試使用插件

以下是我正在使用的代碼:

    TargetOwnedAccount target = new TargetOwnedAccount(); 

        SecurityPrincipal assignee = new SecurityPrincipal(); 
        assignee.Type = SecurityPrincipalType.User; 
        assignee.PrincipalId = context.InitiatingUserId; 

        target.EntityId = ownerGuid; //this is the GUID I am retrieving from the other lookup field 

        AssignRequest assign = new AssignRequest(); 
        assign.Assignee = assignee; 
        assign.Target = target; 

        AssignResponse res = (AssignResponse)crmService.Execute(assign); //this is where i get the exception 

我希望我沒有遺漏任何東西。 任何幫助將不勝感激:) 謝謝

回答

2

好吧,我終於設法解決這個問題。它一直盯着我的臉:P 我在錯誤的地方輸入了錯誤的ID。我需要將'assignee.PrincipalId'設置爲'ownerGuid',然後將'target.EntityId'設置爲當前帳戶ID。新代碼如下:

   TargetOwnedAccount target = new TargetOwnedAccount(); 

       SecurityPrincipal assignee = new SecurityPrincipal(); 
       assignee.Type = SecurityPrincipalType.User; 
       assignee.PrincipalId = ownerGuid; //this is the GUID I am retrieving from the other lookup field 

       target.EntityId = ((Key)entity.Properties["accountid"]).Value; 

       AssignRequest assign = new AssignRequest(); 
       assign.Assignee = assignee; 
       assign.Target = target; 

       AssignResponse res = (AssignResponse)crmService.Execute(assign); 

不敢相信我花了8小時昨天看着它,然後今天我馬上意識到:P

+0

它往往是有益採取暫停和回踩了一會兒;) – ccellar 2012-07-31 08:48:34

+0

是的,你說得對:P – Pawcu 2012-07-31 13:26:52