locked
How to save a CRM record created through ASP.NET. RRS feed

  • Question

  • Hello all, 

          I am creating record through ASP.net. am using  service.create(); to create the record in ASP.Net.  and am successfully able to create the record. but my problem is , am not able to save that record,created through the ASP.net. If i have to retrieve that particular record in ASP.Net, i can't, unless i save that record in the CRM 2011.  Once i create a record through ASP.net i can see that record with all the attributes filled as i exactly wanted.   

    PS: let me know if you need more information on this. i'v many  forms which are communicating with CRM. so every time i create record. i can see the record in CRM but i can not retrieve it unless i save that record in CRM. 

    Tuesday, December 27, 2011 7:08 AM

Answers

  •  

    Hi it may problem from this,

    try this,

     

        ConditionExpression cond1 = new ConditionExpression();
    
                            cond1.AttributeName = "new_email";
    
                            cond1.Operator = ConditionOperator.In;



    By Sanz If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    • Marked as answer by Pradeep47 Thursday, December 29, 2011 6:18 AM
    Thursday, December 29, 2011 5:49 AM

All replies

  • hi what is the exact issue?

    are you able to create in crm or not?>?


    By Sanz If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Tuesday, December 27, 2011 7:12 AM
  • Yes, am a able to create the record in CRM.

    If i create the record directly in CRM  and save it am able to retrieve that record in ASP.net application. but if i create the record through ASP.net Application, the record will be created but not able to retrieve that record. In case if i open that record in CRM and save it only then it reflects in ASP.net.  

    what am suspecting is, when i create the record from ASP.net, the record will be created in CRM but it's NOT SAVED. is there a function to save the file or something similar to that. ??!! may be am wrong.

    Tuesday, December 27, 2011 8:22 AM
  • If a record is created, it is saved in CRM as well. You may want to refresh the Organization service connection. Because of caching the newly created record may not be available when you do a retrieve. Try to set the url to the Organization service once again and use this new service to retrive teh record and that should return the record just created.

    HTH

    Sam


    Web: http://www.inogic.com
    Blog: http://inogic.blogspot.com
    Email: news@inogic.com
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    • Proposed as answer by Sam - Inogic Tuesday, December 27, 2011 9:14 AM
    Tuesday, December 27, 2011 9:14 AM
  • pradeep,

    whenever a record is created a guid will created,

    please check whether a guid is returned from your code or not?

     


    By Sanz If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Tuesday, December 27, 2011 10:40 AM
  • Hello Pujari

    Sam and San are correct

    This is very abnormal that record is saved but created.

     There is no two platform opertion for this .

     if its created then its saved.

    pls clear the browser cache, or better check using filter view

     

     Make sure the CRM server on which you are creating its the same server you are checking the retrieved records

     

    HTH

    dkay

    if the response answered your question, please take a minute and mark the response as an answer.

     

     

    Tuesday, December 27, 2011 12:58 PM
  • Thanks for your replies guys. i really appreciate that. i am racking my head on this. and i tried everything u mentioned, wired thing was while i was checking i found out that, the record IS SAVED(CREATED) IN THE DATABASE AS WELL !!!

    And Yes, am creating and retrieving from same server.  

     

    Am sharing my code which i use to create the record, this is just one feedback form.  pls  let me know if you guys can make pick out any mistake related to my issue from this code.  

         protected void BtnSubmit_Click(object sender, EventArgs e)

            {           

                ClientCredentials Credentials = new ClientCredentials();

                Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;

     

                //This URL needs to be updated to match the servername and Organization for the environment. 

                Uri OrganizationUri = new Uri("http://winXXXXXXXXXXX/XXXXX/XXXXXXXs/2011/Organization.svc");

                Uri HomeRealmUri = null;

     

                //OrganizationServiceProxy serviceProxy;      

                using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, null))

                {

     

                    serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());

                    IOrganizationService service = (IOrganizationService)serviceProxy;

                    Entity feedback = new Entity();

                    feedback.LogicalName = "new_feedback";

                    var val_hospitalEnvironment = ddlhospitalenvironment.SelectedValue;

                    var request = new RetrieveOptionSetRequest

                    {

                        Name = "new_grade"

                    };

                    var retrieveOptionSetResponse = (RetrieveOptionSetResponse)serviceProxy.Execute(request);

                    var retrievedOptionSetMetadata = (OptionSetMetadata)retrieveOptionSetResponse.OptionSetMetadata;

                    var optionList = retrievedOptionSetMetadata.Options.ToArray();

     

                    //DdlNationality.Items.Clear();

                    //DdlNationality.Items.Add("--Select--");

                    //*****************************************************************************************

                    //Hospital Environment

                    foreach (var optionmetadata in optionList)

                    {

                        ddlhospitalenvironment.Items.Add(optionmetadata.Label.LocalizedLabels[0].Label);

                        if (val_hospitalEnvironment == optionmetadata.Label.LocalizedLabels[0].Label)                                  /

                        {

                            int no = (int)optionmetadata.Value;

                            feedback["new_hospitalenvironmentis1"] = new OptionSetValue(no);

                            break;

                        }

                    }

                    //Food Diet

                    var val_fooddiet = ddlfooddiet.SelectedValue;

                    foreach (var optionmetadata in optionList)

                    {

                        ddlfooddiet.Items.Add(optionmetadata.Label.LocalizedLabels[0].Label);

                        if (val_fooddiet == optionmetadata.Label.LocalizedLabels[0].Label)    

                        {

                            int no = (int)optionmetadata.Value;

                            feedback["new_fooddietis1"] = new OptionSetValue(no);

                            break;

                        }

                    }

                    //Hospital Billing

                    var val_hospitalbilling = ddlhospitalbill.SelectedValue;//check

                    foreach (var optionmetadata in optionList)

                    {

                        ddlhospitalbill.Items.Add(optionmetadata.Label.LocalizedLabels[0].Label);

                        if (val_hospitalbilling == optionmetadata.Label.LocalizedLabels[0].Label)                                 

                        {

                            int no = (int)optionmetadata.Value;

                            feedback["new_hospitalbillingis1"] = new OptionSetValue(no);

                            break;

                        }

                    }

                    //Toilet cleaning

                    var val_toi = ddltoiletare.SelectedValue;

                    foreach (var optionmetadata in optionList)

                    {

                        ddltoiletare.Items.Add(optionmetadata.Label.LocalizedLabels[0].Label);

                        if (val_toi == optionmetadata.Label.LocalizedLabels[0].Label)       

                        {

                            int no = (int)optionmetadata.Value;

                            feedback["new_toiletsare1"] = new OptionSetValue(no);

                            break;

                        }

                    }

                    //Over all rating Of clinic

                    var val_overallrating = ddloverallrating.SelectedValue;

                    foreach (var optionmetadata in optionList)

                    {

                        ddloverallrating.Items.Add(optionmetadata.Label.LocalizedLabels[0].Label);

                        if (val_overallrating == optionmetadata.Label.LocalizedLabels[0].Label)                                  /

                        {

                            int no = (int)optionmetadata.Value;

                            feedback["new_overallratingoftheclinic1"] = new OptionSetValue(no);

                            break;

                        }

                    }

                    //service attending doctor

                    var val_serattendingdoctor = ddlattendingdoctor.SelectedValue;

                    foreach (var optionmetadata in optionList)

                    {

                        ddlattendingdoctor.Items.Add(optionmetadata.Label.LocalizedLabels[0].Label);

                        if (val_serattendingdoctor == optionmetadata.Label.LocalizedLabels[0].Label)   /For checking the selected value and the optionset value

                        {

                            int no = (int)optionmetadata.Value;

                            feedback["new_theserviceofattendingdoctoris1"] = new OptionSetValue(no);

                            break;

                        }

                    }

                    //service attending Nurse

                    var val_serattendingnurse = ddlattendentnurse.SelectedValue;

                    foreach (var optionmetadata in optionList)

                    {

                        ddlattendentnurse.Items.Add(optionmetadata.Label.LocalizedLabels[0].Label);

                        if (val_serattendingnurse == optionmetadata.Label.LocalizedLabels[0].Label)   //For checking the selected value and the optionset value

                        {

                            int no = (int)optionmetadata.Value;

                            feedback["new_theserviceofattendentnurseis1"] = new OptionSetValue(no);

                            break;

                        }

                    }

                    //receptionist service

                    var val_receiptionstservice = ddlreciptionistservice.SelectedValue;

                    foreach (var optionmetadata in optionList)

                    {

                        ddlreciptionistservice.Items.Add(optionmetadata.Label.LocalizedLabels[0].Label);

                        if (val_receiptionstservice == optionmetadata.Label.LocalizedLabels[0].Label) //For checking the selected value and the optionset value

                        {

                            int no = (int)optionmetadata.Value;

                            feedback["new_thereciptionistserviceis1"] = new OptionSetValue(no);

                            break;

                        }

                    }

                    //Over all service

                    var val_new_overallserviceis1 = ddloverallrating.SelectedValue;

                    foreach (var optionmetadata in optionList)

                    {

                        ddlreciptionistservice.Items.Add(optionmetadata.Label.LocalizedLabels[0].Label);

                        if (val_new_overallserviceis1 == optionmetadata.Label.LocalizedLabels[0].Label)   //For checking the selected value and the optionset value

                        {

                            int no = (int)optionmetadata.Value;

                            feedback["new_overallserviceis1"] = new OptionSetValue(no);

                            break;

                        }

                    }

                    //Over all feedback

                    var val_totalservice = ddloverallratingservice.SelectedValue;

                    foreach (var optionmetadata in optionList)

                    {

                        ddloverallratingservice.Items.Add(optionmetadata.Label.LocalizedLabels[0].Label);

                        if (val_totalservice == optionmetadata.Label.LocalizedLabels[0].Label)       //For checking the selected value and the optionset value

                        {

                            int no = (int)optionmetadata.Value;

                            feedback["new_overallfeedback1"] = new OptionSetValue(no);

                            break;

                        }

                    }

                    //**********************************************************************************************

     

                    //Storing the Lookup Value 

                    QueryExpression query = new QueryExpression("new_doctor");

                    query.ColumnSet.AddColumns("new_name", "new_doctorid");

                    EntityCollection result1 = serviceProxy.RetrieveMultiple(query);

     

                    var value = ddldoctorname.SelectedValue;

     

                    foreach (Entity doctorname in result1.Entities)

                    {

                        if (value == doctorname.Attributes["new_name"].ToString())

                        {

                            Guid someid = new Guid(doctorname.Attributes["new_doctorid"].ToString());

                            EntityReference erv = new EntityReference();

                            erv.Id = someid;

                            erv.Name = value;

                            feedback["new_doctorsname"] = erv;

                            break;

                        }

                    }

     

                    //Storing the option List value

                    var request_feedback = new RetrieveOptionSetRequest

                    {

                        Name = "new_feedbacktype"

                    };

                    var retrieveOptionSetResponse_feedback = (RetrieveOptionSetResponse)serviceProxy.Execute(request_feedback);

                    var retrievedOptionSetMetadata_feedback = (OptionSetMetadata)retrieveOptionSetResponse_feedback.OptionSetMetadata;

                    var optionList_feedback = retrievedOptionSetMetadata_feedback.Options.ToArray(); 

                    var val_totalservice4 = DropDownList3.SelectedValue;

                    foreach (var optionmetadata_feedback in optionList_feedback)

                    {

                        DropDownList3.Items.Add(optionmetadata_feedback.Label.LocalizedLabels[0].Label);

                        if (val_totalservice4 == optionmetadata_feedback.Label.LocalizedLabels[0].Label)  //For checking the selected  value and the optionset value

                        {

                            int no = (int)optionmetadata_feedback.Value;

                            feedback["new_feedbacktype"] = new OptionSetValue(no);

                            break;

                        }

                    }

                    //Storing a value to the Lookup(PatientID) 

     

                    // QueryExpression query = new QueryExpression("new_patient");

                    QueryExpression query2 = new QueryExpression("new_patient");

                    query2.ColumnSet.AddColumns("new_patientid", "new_name", "new_patient_id");

                    EntityCollection result2 = serviceProxy.RetrieveMultiple(query2);

     

                    foreach (Entity feedback1 in result2.Entities)

                    {

                        var val = PatTextBox.Text;

                        if (val == feedback1.Attributes["new_patient_id"].ToString())

                        {

                            string lmnop = feedback1.Attributes["new_patientid"].ToString();

                            Guid someid = new Guid(lmnop);

     

                            EntityReference erv = new EntityReference();

                            erv.Id = someid;

     

                            feedback["new_patientid"] = erv;

     

                        }

                    }

                    //  Storing dropdown value to the Lookup(Appointment Number) 

                    QueryExpression query5 = new QueryExpression("new_appointment");

                    query5.ColumnSet.AddColumns("new_appointmentnumber", "new_appointmentid", "new_appointmenttime");

                    EntityCollection result5 = serviceProxy.RetrieveMultiple(query5);

                    var value5 = DropDownList2.SelectedValue;

                    foreach (Entity appointment5 in result5.Entities)

                    {

                        if (value5 == appointment5.Attributes["new_appointmentnumber"].ToString())

                        {

                            string lmnop = appointment5.Attributes["new_appointmentid"].ToString();

                            Guid someid = new Guid(lmnop);

                            EntityReference erv = new EntityReference();

                            erv.Id = someid;

                            erv.Name = value5;

                            feedback["new_appointmentnumber"] = erv;

                             string date_1 = appointment5.Attributes["new_appointmenttime"].ToString();

                            //Convert.ToDateTime(date_1);

                            string subdate = date_1.Substring(0,10);

     

                            feedback["new_appointmentdate"] = subdate;

                            break;

                        }

                    }

                    feedback["new_name"] = txtfirstname.Text.ToString();

                    feedback["new_lastname"] = txtlastname.Text.ToString();

                    feedback["new_contactnumber1"] = txtcontactnumber.Text.ToString();

                    //  feedback["new_doctorsnamename"] = value.ToString();

                    feedback["new_email"] = txtmailid.Text.ToString();

                    //feedback["new_doctorsname"] = exv;

     

                    Guid feedbackid = service.Create(feedback);

                    //refreshing The Pagehttp://localhost:30027/PRM/About.aspx

                       feedback["new_date"] = System.DateTime.Now;

                     Response.Redirect(Request.RawUrl);

                 };

            }

    }

    }

     


    • Edited by Pradeep47 Wednesday, December 28, 2011 6:42 AM
    Wednesday, December 28, 2011 6:38 AM
  • have you got the guid, and how it is displaying({xxxx-xxxx})?,

    might be guid contains "{" and "}",

    where do you need to redirect,

     


    By Sanz If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    • Edited by san Sanz Wednesday, December 28, 2011 7:20 AM
    Wednesday, December 28, 2011 7:20 AM
  • Yes, i have got the Guid and it's not displaying like this. ({xxxx-xxxx-xxxxxx-xxxxx}).  I don't need to redirect any where. i am just trying to create a record. and its' happening successfully.   I have a GridView which list all the feedbacks. there  the record details are not showing up, unless i save that particular record in CRM.  

    Wednesday, December 28, 2011 8:59 AM
  • You need to redbind your custom grid by reading the records once again from CRM. When you call the retrieve function make sure you create the proxy once again i.e do not use the existing proxy but add this line once again

     

    OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, null))

    Now call the retrieve method using this new Proxy. That would return you the results. I still believe this is a caching issue. And refreshing or reconnecting the service proxy would return the latest information inthe database.

    HTH

    Sam


    Web: http://www.inogic.com
    Blog: http://inogic.blogspot.com
    Email: news@inogic.com
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    • Proposed as answer by Sam - Inogic Wednesday, December 28, 2011 9:09 AM
    Wednesday, December 28, 2011 9:09 AM
  • Pradeep,

    as per my knowledge,Problem with loading function,

    on load function are you checking any ispostback in load or not?

     


    By Sanz If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Wednesday, December 28, 2011 9:30 AM
  • Hi

    Did this help?

    Please make sure to mark as answer to the response that helped you get through. This will help others with similar problem identify the answer and also close this thread as resolved.

    Thanks

    Dkay

    Wednesday, December 28, 2011 11:10 AM
  • It's good to know that you guys are responding so well. that makes me not to quit on this. am sharing my Gridview code where am trying to retrieve  the feedback record information.  This is my original code, i've tried your suggestions in same code though.  Pls let me know where i have to make changes to retrieve  the latest record from the database. 

     

     protected void Page_Load(object sender, EventArgs e)

            {

                if (!IsPostBack)

                {

                    GridView1.DataBind();

                }          

                     try

                    {

                        ClientCredentials Credentials = new ClientCredentials();

                        Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;

                        //This URL needs to be updated to match the servername and Organization for the environment. 

                        Uri OrganizationUri = new Uri("http://xxxxxxxxxxxxxxx/xxxxxxx/Xxxxxxx/2011/Organization.svc");

                        Uri HomeRealmUri = null;

     

                        //OrganizationServiceProxy serviceProxy;        

                        using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, null))

                        {

                            IOrganizationService service = (IOrganizationService)serviceProxy;

                            ConditionExpression cond1 = new ConditionExpression();

                            cond1.AttributeName = "new_email";

                            cond1.Operator = ConditionOperator.Equal;

     

                           string mailid = Convert.ToString(Session["MailID"]);

                            cond1.Values.Add(mailid);

                            FilterExpression filter = new FilterExpression();

                            //set the properties ofthe filter.

                            filter.Conditions.Add(cond1);

                            //create the query expression object.

                            QueryExpression query = new QueryExpression("new_feedback");

                            //set the query expression 

                            query.ColumnSet.AddColumns("new_doctorsname", "new_date", "new_overallfeedback1");

                            query.Criteria.AddFilter(filter);

                            EntityCollection result1 = service.RetrieveMultiple(query);

                            DataTable dt = new DataTable();

     

                            DataColumn dc_doctorsname = new DataColumn("Doctor Name");

                            DataColumn dc_date = new DataColumn("Date");

                            DataColumn dc_overallfeedback1 = new DataColumn("Over All Feedback");

     

     

                            dt.Columns.Add(dc_doctorsname);

                            dt.Columns.Add(dc_date);

                            dt.Columns.Add(dc_overallfeedback1);

     

     

                            foreach (Entity patient in result1.Entities)

                            {

                                DataRow dr;

                                dr = dt.NewRow();

                                EntityReference course_guid = (EntityReference)(patient.Attributes["new_doctorsname"]);

                                dr["Doctor Name"] = course_guid.Name;

                               

                              string tempdate = patient.Attributes["new_date"].ToString();

                                dr["Date"] = tempdate.Substring(0, 9);

     

           string semester_string = ((OptionSetValue)(patient.Attributes["new_overallfeedback1"])).Value.ToString();

                                int semester_int = Convert.ToInt32(semester_string);

             dr["Over All Feedback"] = GetOptionsSetTextOnValue(service, "new_feedback", "new_overallfeedback1", semester_int);

     

                                dt.Rows.Add(dr);

                                GridView1.DataSource = null;

                                GridView1.DataSource = dt;

                               GridView1.DataBind();

                           }

                        }

                    }

                    catch (Exception ex) { }

                }

     





    • Edited by Pradeep47 Thursday, December 29, 2011 5:30 AM
    Thursday, December 29, 2011 5:16 AM
  •  

    Hi it may problem from this,

    try this,

     

        ConditionExpression cond1 = new ConditionExpression();
    
                            cond1.AttributeName = "new_email";
    
                            cond1.Operator = ConditionOperator.In;



    By Sanz If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    • Marked as answer by Pradeep47 Thursday, December 29, 2011 6:18 AM
    Thursday, December 29, 2011 5:49 AM
  • Thanks alot  San,  you are  my savior. My issue has been resolved and am marking this thread as "Answered " n closing it.  Thanks all you  guys for your valuable advice.  c ya
    Thursday, December 29, 2011 6:32 AM
  • you always welcome,

     


    By Sanz If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Thursday, December 29, 2011 6:39 AM