Answered Callout PostUpdate

  • 13 มีนาคม 2551 19:29
     
     

     

    Hi

    Any code samples  for Callouts  PostUpdtes  to  Update the Entity Records

     

    Thanks

    shaik

ตอบทั้งหมด

  • 14 มีนาคม 2551 2:50
    ผู้ดูแล
     
     คำตอบ
    Hi shaik,

    there is nothing special about updating entities in a plug-in. The only difference to be aware of is how to obtain CRM service reference. In "normal" code you'd use something like:

    CrmService service = new CrmService();

    In a plug-in, you'd use:

    ICrmService service = context.CreateCrmService();

    The rest is identical, i.e. use ICrmService the same way as you would CrmService.

    As you intend to update entity in a post update, and if it happens to be the same entity, retrieving service from the context becomes very important because recursion and nesting in plug-ins is taken care of. For example, context has a property called Depth which indicates "nesting" level. You can check it and abort your plug-in if it's more than 1:

    if(context.Depth > 1) ...

    If you don't do anything, CRM will stop any recursion above 8.

    There is one more gotcha: the above applies to plug-ins executing in a parent pipeline. If your plug in is executed on a child pipeline then you won't be able to use context.CreateCrmService. Instead, follow sample code that you can download here.

    I did assume that you're using CRM 4, however. Please let us know if that's not the case and we'll try to help you out with CRM 3.

    Hope this helps
    George
    • ทำเครื่องหมายเป็นคำตอบโดย Jim Glass Jr 7 มกราคม 2553 19:51
    •  
  • 14 มีนาคม 2551 12:18
    ผู้ดูแล
     
     

     

    see this

     

    public override void PostUpdate(
          CalloutUserContext userContext,
          CalloutEntityContext entityContext,
          string preImageEntityXml,
          string postImageEntityXml)
       {
      
          XmlDocument entityDoc;
          try
          {
             entityDoc = new XmlDocument();
             entityDoc.LoadXml(postImageEntityXml);
      
             string nameSpaceValue = entityDoc.ChildNodes[0].Attributes
                ["xmlns"].Value;
             XmlNamespaceManager xsn = new
                XmlNamespaceManager(entityDoc.NameTable);
             xsn.AddNamespace("z," nameSpaceValue);
      
             string entityXpath = "//z:BusinessEntity";
             XmlNode businessEntityNode =
                entityDoc.SelectSingleNode(entityXpath, xsn);
                      
             string businessEntityName =
                ((XmlElement)businessEntityNode).
                GetAttribute("Name").ToString();
      
             switch (businessEntityName.Trim().ToLower().ToString())
             {
                case MSCRMLEAD:
                   ProcessLeads(preImageEntityXml, postImageEntityXml);
                   break;
                default:
                   break;
             }
          }
          catch (Exception ex)
          {
             //TODO :Log exceptions to Event log
          }
          finally
          {
             entityDoc = null;
          }
       }

     

    Regards,

    Imran

     

    http://microsoftcrm3.blogspot.com