2013-04-23 32 views
0

我在術後女巫插件需要通過Web服務在SharePoint上創建一個文件夾,要做到這一點,我的插件調用Web服務執行FechXML擺脫實體的信息,但問題是,實體仍然沒有存在,它給我空。如何強制後操作插件提交?

如何強制插件提交/數據保存到我的FechXml工作?

插件代碼:

try 
    { 
     Entity entity; 
     if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) 
     { 
      entity = (Entity)context.InputParameters["Target"]; 
      if (entity.LogicalName != "fcg_processos") 
      { 

       throw new InvalidPluginExecutionException("Ocorreu um erro no PlugIn Create Folder."); 
      } 
     } 
     else 
     { 

      throw new InvalidPluginExecutionException("Ocorreu um erro no PlugIn Create Folder."); 
     } 

     processosid = (Guid)((Entity)context.InputParameters["Target"])["fcg_processosid"]; 
     string processoid2 = processosid.ToString(); 


     PluginSharepointProcessos.ServiceReference.PrxActivityResult result = log.CreateFolderSP("Processo", processoid2); 

     string resultado = result.xmlContent; 

     if (result.retCode > 0) 
     { 
      throw new InvalidPluginExecutionException("Ocorreu um erro na criação do Folder do Processo."); 

     } 

WEBSERVICE CODE:

{   
      //WEBSERVICE TO CALL XML FROM ENTITY 
      PrxActivityResult Processo = ProcessoFetch2("", "", guid); 
      string stxml; 
      stxml = Processo.XmlContent; 
      XmlDocument xmlDoc = new XmlDocument(); 
      xmlDoc.LoadXml(stxml); 
      XmlNodeList nodeList = xmlDoc.SelectNodes("resultset/result"); 
      List<string[]> lista = new List<string[]>(); 
      string[] strs = new string[7]; 
      if (nodeList.Count != 0)//verificar o numero de registos 
      { 

       foreach (XmlNode xmlnode in nodeList) 
       { 
        if (xmlnode.SelectSingleNode("//fcg_numero") != null) 
         strs[2] = xmlnode.SelectSingleNode("//fcg_numero").InnerText; 
        else 
         strs[2] = ""; 

        if (xmlnode.SelectSingleNode("//Concurso.fcg_numero") != null) 
         strs[3] = xmlnode.SelectSingleNode("//Concurso.fcg_numero").InnerText; 
        else 
         strs[3] = ""; 
       } 

      } 

     IwsspClient FmwSharepoint = new IwsspClient(); 
     PrxActivityResult folderresult = new PrxActivityResult(); 

     List<ws.fcg.sipp.svc.ServiceReferenceSharePoint.PareChave> arrayfields = new List<ws.fcg.sipp.svc.ServiceReferenceSharePoint.PareChave>(); 

     ws.fcg.sipp.svc.ServiceReferenceSharePoint.PareChave nprocesso = new ws.fcg.sipp.svc.ServiceReferenceSharePoint.PareChave(); 
     nprocesso.Key = "FCG_Numero_Processo"; 
     nprocesso.value = strs[2]; 
     arrayfields.Add(nprocesso); 

     ws.fcg.sipp.svc.ServiceReferenceSharePoint.PareChave npconcurso = new ws.fcg.sipp.svc.ServiceReferenceSharePoint.PareChave(); 
     npconcurso.Key = "FCG_Numero_Concurso"; 
     npconcurso.value = strs[3]; 
     arrayfields.Add(npconcurso); 

     ws.fcg.sipp.svc.ServiceReferenceSharePoint.PareChave npguid = new ws.fcg.sipp.svc.ServiceReferenceSharePoint.PareChave(); 
     npguid.Key = "FCG_Guid_CRM"; 
     npguid.value = guid; 
     arrayfields.Add(npguid); 

     folderresult = FmwSharepoint.CreateFolder("http://localhost/folder", "Processos", strs[2], arrayfields.ToArray()); 

     res = folderresult; 
     } 
+1

如果你正在一個實體上進行後期操作,根據定義它是在交易之後。此外,如果您從當前實體檢索數據,則您擁有該插件的數據只應從上下文和前/後圖像中獲取數據,因此您無需再撥打其他電話。如果你顯示你的代碼,其他人也可以更容易地幫助你。 – 2013-04-23 12:45:31

+0

我只是用代碼編輯帖子。 – 2013-04-23 13:43:02

+0

我沒有看到您實際執行FetchXml查詢的位置。那是在ProcessoFetch2中嗎? – Daryl 2013-04-23 14:11:38

回答

2

當一個插件在後操作運行時,它仍然是數據庫事務中,它有沒有實際一直致力於數據庫。任何與作爲插件上下文的一部分傳入的服務引用進行的調用將在數據庫事務的上下文中執行,您將能夠檢索新創建/更新的值。如果你創建了一個全新的OrganizationServiceProxy(我猜測你正在做的),它將在數據庫事務之外執行,並且不會看到新創建/更新的值。

作爲@AndyMeyers在他的評論(這應該是一個回答恕我直言)建議,通過前/後圖像從插件上下文獲取數據或目標是理想的,因爲它消除了另一個數據庫調用。如果您不得不查找可能由之前激發的另一個插件創建的記錄,則需要使用插件上下文中包含的IOrganizationService。

+0

+1用於糾正我的帖子插件仍在交易中。在以前的CRM版本(4.0)中,這是不正確的,我想我把我的電線弄混了。 – 2013-04-23 13:12:30

0

我沒有選擇,我用這個代碼來運行基於圖像的web服務而忘記了FecthXml,如前所述,我得到的所有信息從崗位操作的圖像,併發送回的WebService。謝謝,這裏是代碼:

entity = (Entity)context.InputParameters["Target"]; 

      concursid = (Guid)entity.Attributes["fcg_concursid"]; 
      guid = concursid.ToString(); 

      string npconcurs = (string)entity.Attributes["fcg_numer"]; 
      nconcurs= npconcurs; 

      EntityReference nprograma = (EntityReference)entity.Attributes["fcg_unidadeorganica"]; 

      program = nprogram.Name; 

      if (entity.LogicalName != "fcg_concurs")