locked
Customization of Code in web app to migrate to crm 2013 using c# RRS feed

  • Question

  • Hi All .

    I just want to know what could be the replacement of the following code that can 

    be used for crm 2013 for custom web application.

    the following code is part of mscrm 4.0 , and my requirement is to upgrade 

    the following code to as per crm 2013 .

                        // Create the target object for the request.
                        TargetRetrieveAnnotation target = new TargetRetrieveAnnotation();

                        // Set the properties of the target object.
                        // EntityId is the GUID of the record being retrieved.                    
                        target.EntityId = new Guid(annotationId);

                        // Create the request object.
                        RetrieveRequest retrieve = new RetrieveRequest();

                        // Set the properties of the request object.
                        retrieve.Target = target;
                        retrieve.ColumnSet = cols;

    any help will be appreciable , i am a new guy in this .

    Thursday, January 8, 2015 12:05 PM

All replies

  • Hello,

    You can use following code:

    Entity annotation = service.Retrieve("annotation", <Id of annotation to Retreive>, new ColumnSet(true));


    Dynamics CRM MVP/ Technical Evangelist at SlickData LLC
    My blog

    Thursday, January 8, 2015 12:12 PM
    Moderator
  • Dear Friend ,

    Immediate after that code which you have given i also used it .

    but i asked detail discussion of above code to be changed as per crm 2013, 

    because i didn't understand that mscrm 4.0 code.


    • Edited by EmpAnsar Thursday, January 8, 2015 12:27 PM
    Thursday, January 8, 2015 12:27 PM
  • there is a big difference between CRM 4.0 Web Services and the one for CRM 2011/2013/2015.

    One difference is the one you just wrote. In CRM 4.0 there were many methods to retrieve data from a particular entity (in your case Annotation - note), starting from CRM 2011 they introduced a standard way (the service.Retrieve) to read the data from CRM (assuming you know the logicalname of the entity and the GUID)


    My blog: www.crmanswers.net - Rockstar 365 Profile

    Thursday, January 8, 2015 12:56 PM
  • Yes friend.

    But in my scenario the code is written in mscrm 4.0

    and i want to change that as per crm 2013 as of now.

    in my scenario i want to do out of CRUD only RU , so how 

    can i change the code.

    in my requirement there are some people which are to be added note base on condition.

    i do need help in that scenario.

    Thursday, January 8, 2015 1:15 PM
  • Dear Friend the following is my code that i need to change

      protected void btnUpload_Click(object sender, EventArgs e)
        {
            /* create an annotation record with
             * filename
             * filesize
             * isdocument
             * documentbody
            */
            bool isUpdateAnnotation = false;
            string filePath = FileUpload1.PostedFile.FileName;
            //service =  CRMServiceUtility.GetCrmServiceByLoggedInUser(_serverURL, _organisation,new Guid(loggedInUser));
            service = CRMServiceUtility.GetCrmServiceByLoggedInUser(_serverURL, _organisation, new Guid("01358bb4-151c-e111-8032-bc305ba74173"));

            if (filePath.Length > 0)
            {
                string fileExtn = filePath.Substring(filePath.LastIndexOf("."));
                if (fileExtn.Equals(".pdf") || fileExtn.Equals(".PDF") || fileExtn.Equals(".doc") || fileExtn.Equals(".DOC") || fileExtn.Equals(".docx") || fileExtn.Equals(".DOCX"))
                {
                    string fileType = rdBtnType.SelectedItem.Text;
                    string fileName = filePath.Substring(filePath.LastIndexOf("\\") + 1);
                    string body = Utility.EncodeFileToBase64(FileUpload1);
                    string mimeType = Utility.getMimeType(filePath);

                    RetrieveMultipleResponse screening = Entity.retriveEntityCollection(fields, "objectid", screeningId, "annotation");
                  //RetrieveMultipleResponse screening = getEntityDetails("annotation", "objectid", screeningId);
                    int count = screening.BusinessEntityCollection.BusinessEntities.GetLength(0);

                    for (int i = 0; i < count; i++)
                    {
                        annotation annotationEntity = (annotation)screening.BusinessEntityCollection.BusinessEntities[i];
                        //annotationId = ((CrmSDK.Key)((CrmSDK.KeyProperty)annotationEntity.Properties[0]).Value).Value.ToString();
                        annotationId = annotationEntity.annotationid.Value.ToString();
                        // Create the column set object that indicates the fields to be retrieved.
                        ColumnSet cols = new ColumnSet();

                        // Set the properties of the column set.
                        cols.Attributes = new string[] { "subject" };

                        // Create the target object for the request.
                        TargetRetrieveAnnotation target = new TargetRetrieveAnnotation();

                        // Set the properties of the target object.
                        // EntityId is the GUID of the record being retrieved.                    
                        target.EntityId = new Guid(annotationId);

                        // Create the request object.
                        RetrieveRequest retrieve = new RetrieveRequest();

                        // Set the properties of the request object.
                        retrieve.Target = target;
                        retrieve.ColumnSet = cols;

                        // Execute the request.
                       RetrieveResponse retrieved = (RetrieveResponse)service.Execute(retrieve);

                        annotation tempAnnotation = (annotation)retrieved.BusinessEntity;
                        if (tempAnnotation.subject != null)
                        {
                            if (tempAnnotation.subject.Equals(fileType))
                            {
                                isUpdateAnnotation = true;
                                break;
                            }
                       }
                    }
                    if (isUpdateAnnotation)
                    {
                       //update the exixting annotation
                        annotation updateAttachment = new annotation();
                        updateAttachment.mimetype = mimeType;
                        updateAttachment.filename = fileName;
                        updateAttachment.documentbody = body;
                        updateAttachment.annotationid = new CrmSDK.Key();
                       updateAttachment.annotationid.Value = new Guid(annotationId);

                        service.Update(updateAttachment);
                    }
                    else
                    {
                        //add this document------ create a record for annotation
                        annotation attachment = new annotation();
                        attachment.isdocument = new CrmSDK.CrmBoolean();
                        attachment.isdocument.Value = true;
                        attachment.subject = fileType;
                        attachment.mimetype = mimeType;
                       attachment.filename = fileName;
                       attachment.documentbody = body;
                       attachment.objecttypecode = new EntityNameReference();
                        attachment.objecttypecode.Value = "new_screening";
                      attachment.objectid = new Lookup();
                        attachment.objectid.Value = new Guid(screeningId);

                        Guid annotationid = service.Create(attachment);

                        //update screening entity document attach status
                        new_screening screeningEntity = new new_screening();
                        if (rdBtnType.SelectedValue == "0")
                      {
                           screeningEntity.new_nondisclosureattached = new CrmSDK.CrmBoolean();
                            screeningEntity.new_nondisclosureattached.Value = true;
                       }
                       else
                       {
                            if (rdBtnType.SelectedValue == "1")
                          {
                                screeningEntity.new_confirmationattached = new CrmSDK.CrmBoolean();
                                screeningEntity.new_confirmationattached.Value = true;
                                screeningEntity.new_stage = new Picklist();
                                screeningEntity.new_stage.Value = 5;
                            }
                        }

                        screeningEntity.new_screeningid = new CrmSDK.Key();
                        screeningEntity.new_screeningid.Value = new Guid(screeningId);

                        service.Update(screeningEntity);
                    }
                    
                   lblError.Text = "Attachment Succesful";
                }
                else
                {
                    lblError.Text = "Attach only .pdf or .doc(x) file";
               }
        }
            else
            {
                //display msg "You must specify a file to attach"
                lblError.Text = "You must specify a file to attach";
            }
        }

    Thursday, January 8, 2015 1:20 PM
  • HI ALL.

    Can anybody tell me what could be the replacement of the following line of code that is 

    as per crm 4.0 but i want to change that as per crm 2013.

    only i am confused with highlighted code

      // Create the target object for the request.
                        TargetRetrieveAnnotation target = new TargetRetrieveAnnotation();

                        // Set the properties of the target object.
                        // EntityId is the GUID of the record being retrieved.                    
                        target.EntityId = new Guid(annotationId);

                        // Create the request object.
                        RetrieveRequest retrieve = new RetrieveRequest();

                        // Set the properties of the request object.
                        retrieve.Target = target;
                        retrieve.ColumnSet = cols;

                        // Execute the request.
                        RetrieveResponse retrieved = (RetrieveResponse)service.Execute(retrieve);


    Friday, January 9, 2015 4:37 AM
  • Please, don't create duplicated threads.

    Btw - I provided replacement code you are asking about. I can paste it here again if you haven't seem my message:

    Entity annotation = service.Retrieve("annotation", <Id of annotation to Retreive>, new ColumnSet(true));


    Dynamics CRM MVP/ Technical Evangelist at SlickData LLC
    My blog


    Friday, January 9, 2015 5:52 AM
    Moderator
  • Sorry for inconvenience.

    Actually i wanted to get the annotation for update or create a new based on some conditions .

    thats why i have written in multiple thread , did u saw above code . that is from old crm 4.0 

    now i want to change that code as per crm 2013.

    i didn't understand the concepts in crm 4.0 thats why i have pasted that full code.

    any help will be appreciable if i could get some more code as replace of the above code.

    • Edited by EmpAnsar Friday, January 9, 2015 10:23 AM
    Friday, January 9, 2015 10:15 AM
  • Hi HudiBaba,

    I would like to say before converting CRM 4.0 plugins to CRM 2013 Plugins you should explore the architecture of MS CRM 4.0 vs CRM 2011. Most of the things in CRM 4.0 were specific to that only for instance datatype " crmdatetime","key" etc. Now from MS CRM 2011 onwards it uses standard .Net framework.

    Refer Belows links

    http://microxrm.blogspot.in/2014/12/microsoft-dynamics-crm-40-to-20112013.html

    http://weblogs.asp.net/gayanperera/5-syntax-changes-in-dynamics-crm-2011-plugins

    Hope it helps,


    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Thanks and Regards, Mohammad Yusuf Ansari http://microxrm.blogspot.in

    Sunday, January 11, 2015 6:25 AM