如何在操作后强制插件提交?

时间:2013-04-23 12:28:53

标签: plugins dynamics-crm-2011

我有一个后期操作插件,需要通过webservice在sharepoint上创建一个文件夹,为此,我的插件调用webservice来执行FechXML以从实体获取信息,但问题是该实体仍然存在不存在,它给我Null。

如何强制插件将数据提交/保存到我的FechXml中?

PLUGIN CODE:

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;
        }

2 个答案:

答案 0 :(得分:2)

当插件在后操作上运行时,它仍然在数据库事务中,并且实际上它尚未提交到数据库。作为插件上下文的一部分传入的服务引用所做的任何调用都将在数据库事务的上下文中执行,您将能够检索新创建/更新的值。如果你创建一个全新的OrganizationServiceProxy(我猜你正在做什么),它将在数据库事务之外执行,并且不会看到新创建/更新的值。

正如@AndyMeyers在他的评论中建议的那样(这应该是IMHO的答案),通过前/后图像或目标从插件上下文中获取数据是理想的,因为它消除了另一个数据库调用。如果您必须查找可能由之前触发的另一个插件创建的记录,则需要使用插件上下文中包含的IOrganizationService。

答案 1 :(得分:0)

我没有选择,我使用此代码运行基于图像的webservice并忘记了FecthXml,如上所述,我从post操作上的Image获取所有信息并发送回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")