locked
How to Programatically create records for Particular custom entity record in CRM RRS feed

  • Question

  • Hi,

    How to Programatically create records for Particular custom entity record in CRM.

    For Example I have patient case custom entity, I want to create Audit entity records for

    particular patient case (guid).

    Any help appriciate...

     

    Thanks

    Srikanth

     

     

    Tuesday, August 3, 2010 5:59 PM

Answers

All replies

  • Hi, Srikanth.

     

    Check this accelerator - http://crmaudit.codeplex.com/


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Tuesday, August 3, 2010 6:17 PM
    Moderator
  • Hi,

     

    Thanks for your replies, I want to write the code in custom aspx page.

    could you help on the same.

     

    Thanks

    Srikanth

    Tuesday, August 3, 2010 6:35 PM
  • You can use this article as a start point.

    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Tuesday, August 3, 2010 6:44 PM
    Moderator
  • Hi Andriy,

     

    For Example I have patient case custom entity, I want to create Audit entity records for

    particular patient case (guid), this is my actual requirements..

     

    Thanks

    Srikanth

    Tuesday, August 3, 2010 6:51 PM
  • Hi Andriy,

    I need to create the records programatically in to the Audit Enitity based upon the selection of

    Patient case (GUID), Please send me the code, this is very urgent..

    --Patient Case (Enitiy)

                  | (GUID)

         ---Audit (Enitity)

               -- Record1

    Thanks

    Srikanth

    Tuesday, August 3, 2010 7:50 PM
  • Patient case (GUID), Please send me the code, this is very urgent..

    --Patient Case (Enitiy)

                  | (GUID)

         ---Audit (Enitity)

               -- Record1

    You should develop the code. Or you are not developer?

    Anyway I can only help but not to do your work ;)


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Tuesday, August 3, 2010 7:52 PM
    Moderator
  • Andriy,

    I am newbie to the CRM domain, Please help me on the same.

    Thanks

    Srikanth

     

    Tuesday, August 3, 2010 8:00 PM
  • You should download SDK and try to develop something.

    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Tuesday, August 3, 2010 8:33 PM
    Moderator
  • Hi Andriy,

     

    I think you understood my requirement, I am able to add the records programatically to the audit entity.

    But, I need to create new Audit record for particular Patient Case (GUID). . I am sending the code, please I have a look at it..

     

    using

    System.Web;

    using

    System.Web.Security;

    using

    System.Web.UI;

    using

    System.Web.UI.HtmlControls;

    using

    System.Web.UI.WebControls;

    using

    System.Web.UI.WebControls.WebParts;

    using

    System.Web.Services.Protocols;

    using

    SDK = Tectura.Crm.Common.Sdk.CrmServiceSdk;

    using

    Tectura.Crm.Common.Sdk.CrmServiceSdk;

    using

    Tectura.Crm.Common;

    using

    Tectura.Crm.Common.Utility;

    using

    System.IO;

    using

    System.Xml;

    using

    Microsoft.Win32;

    using

    System.Reflection;

     

    public

    partial class AddAudit : System.Web.UI.Page

    {

     

    private SDK.CrmService _service = null;

     

    private string _orgName = string.Empty;

     

    private Guid _userId = Guid.Empty;

     

    private Guid _infusionid = Guid.Empty;

     

    protected void Page_Load(object sender, EventArgs e)

     

    try

    {

    _orgName = GetOrganization();

    _userId = GetCurrentUserID();

    setAuditRecords();

    }

     

    catch (Exception ex)

     

    public void setAuditRecords()

    //here I need to enter the records based upon the GUID.. of the Patient profile entity

    StringProperty entitydisplayname = new StringProperty(); 

    "custom_entity_label"; 

    "MyEntity"; 

    StringProperty entity = new StringProperty();  

    "custom_entity";

     

    "Reddy";

     

    StringProperty action = new StringProperty();

     

    "custom_message";

     

    "Myaction";

     

    StringProperty entityID = new StringProperty();

     

    "custom_entityid";

     

    "ED5284B1-B03D-DF11-9B91-005056AE59BD";

     

    StringProperty primaryAttribute = new StringProperty();

     

    "custom_primary_attribute";

     

    "PP-Abesada-TerkGuillermo-62659";

     

    // Create the DynamicEntity object.

     

    DynamicEntity pcontactEntity = new DynamicEntity();

     

    // Set the name of the entity type.

    pcontactEntity.Name =

    "custom_audit";

     

    // Create the DynamicEntity object.

     

    DynamicEntity contactEntity = new DynamicEntity();

     

    // Set the name of the entity type.

    contactEntity.Name =

    "custom_audit";

     

    // Set the properties of the contact.

    contactEntity.Properties =

    new Property[] { entitydisplayname, entity, action, entityID, primaryAttribute};

     

    // Create the target.

     

    TargetCreateDynamic targetCreate = new TargetCreateDynamic();

     

    // Create the request object.

     

    CreateRequest create = new CreateRequest();

     

    // Set the properties of the request object.

    create.Target = targetCreate;

     

    // Execute the request.

     

    CreateResponse created =(CreateResponse)_service.Execute(create);

     

    private string GetOrganization()

     

    string org = "";

     

    RegistryKey regkey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\MSCRM");

     

    "CustomWebFormOrganization").ToString();

     

    return org;

     

    private Guid GetCurrentUserID()

     

    this._service = CrmUtility.CreateCrmService(_orgName);

     

    string result = "";

     

    string fetchXml = @"

     

    ;

     

    //Format the fetch XML

     

    // SDK.CrmService crmservice = new Ascentium.Crm.Common.Sdk.CrmServiceSdk.CrmService();

    result = _service.Fetch(fetchXml);

     

    int start = result.IndexOf("<systemuserid>");

     

    int end = result.IndexOf("</systemuserid>");

     

    //start += 10;

    end -= (start - 15);

    result = result.Substring(start, end);

    result = result.Replace((

    "<systemuserid>"), "");

     

    "</systemuserid>", "");

     

    return new Guid(result);

     

    }

     

     

     

     

    }

     

    result = result.Replace(

     

     

     

    <fetch mapping=""logical"">

    <entity name=""systemuser"">

    <attribute name=""systemuserid"" />

    <filter>

    <condition attribute=""systemuserid"" operator=""eq-userid"" />

    </filter>

    </entity>

    </fetch>

    "

     

     

    {

     

    }

     

     

    org = regkey.GetValue(

     

    {

     

    }

     

     

    targetCreate.Entity = contactEntity;

     

     

     

     

     

     

     

    primaryAttribute.Value =

    primaryAttribute.Name =

     

    entityID.Value =

    entityID.Name =

     

    action.Value =

    action.Name =

     

    entity.Value =

    entity.Name =

     

    entitydisplayname.Value =

    entitydisplayname.Name =

    {

     

     

    {

    }

    }

     

     

    Thanks

    Srikanth Reddy

     

     

     

     

     

     

     

     

    Wednesday, August 4, 2010 10:48 AM