web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to Set Lookup value using Plugin

(0) ShareShare
ReportReport
Posted on by

Hi,

My customizations are like this.

I use PhoneCall, when PhoneCall is Succeeded a new record in the Custom Entity gets created.

At the same time if any attachments attached to PhoneCall has to get attached to the new record which got created.

 For this i found that if we update the ObjectId in Annotation Entity with the Created recordId attachments gets attached to the record.

My code to Update ObjectId in Annotation Entity throws an error "server was unable to process request"

Please find the code below:

// Create the annotation object.

annotation an = new annotation();

// Set the annotation ObjectId to created recordId

Lookup objectID = new Lookup();

objectID.Value = new Guid("213F6990-9770-DF11-8983-00155D01D806");

an.objectid = objectID;

// The aannotationId is a key that reference Id of the annotation to be updated.

an.annotationid = new Key();

// The annotationid.Value is the GUID of the record to be changed.

an.annotationid.Value = new Guid(Anotationid);

// Update the annotation.

try

{

service.Update(an);

}

catch (System.Web.Services.Protocols.SoapException ex)

{

 

Suggest me where i am missing.

 

Regards

Prashanth Y

 

*This post is locked for comments

I have the same question (0)
  • Inogic Profile Picture
    703 on at

    Hi Prashanth,

    In a Lookup you need to set the id as well as the object type. You have only provided the id and not the object type. The object type of your custom entity needs to be provided in the below code.

    Lookup objectID = new Lookup();

    objectID.Value = new Guid("213F6990-9770-DF11-8983-00155D01D806");

    Also by what you are currently doing, you are "moving" the attachments to the new custom entity and not "copying" it. So these attachment would now only be available in the custom entity and not in the phone call.

    HTH

    Sam 

     

  • Prashanth Yerramsetty Profile Picture
    on at

    Hi Sam,

    You are correct i am not copying the attachments to custom entity, but just moving from PhoneCall entity to New Custom Entity record.

    The problem i am facing here, I need to upadte the ObjectId (column) in the annotationbase table in database with the newly created CustomEntity record GUID. 

    In order to update it i need to set the lookup values using ID and ObjectType i dont know the to which ObjectType the column ObjectId Refers to. Can you help me in resolving this.

    Thanking You,

    With Regards,

    Prashanth Y.

     

  • Inogic Profile Picture
    703 on at

    Hi Prashanth,

    The Object Type would be the name of the custom entity of which the object id is being provided.

    HTH

    Sam

  • Prashanth Yerramsetty Profile Picture
    on at

    Hi Sam,

    The ObjectId column in the annotationbase table is not a referenced  column. thats the problem i am unable to set the value to it. Do you have any input for me how to the find the ObjectType for it or how to set the value to lookup for the column ObjectID.

    Regards

    Prashanth Y 

     

     

  • Inogic Profile Picture
    703 on at

    Hi Prashanth,

    You need to set the objectid and object type using the following code.

    Replace the entity name "account" in the below snippet to the name of your custom entity.

      //set the type of entity to which the note is to be associated //here we selected account
                objectID.type = EntityName.account.ToString();
                an.objectid = objectID;
           //sets the type of entity with which the note is associated.
                an.objecttypecode = new EntityNameReference(EntityName.account.ToString());

    HTH

    Sam

  • Prashanth Yerramsetty Profile Picture
    on at

    Hi Sam,

     I get Error at this line

     

    an.objecttypecode = new EntityNameReference(EntityName.account.ToString());

    Error:  'CrmSdk.EntityNameReference' does not contain a constructor that takes '1' arguments C:\Users\crmvendor\Documents\Visual Studio 2008

    Regards

    Prashanth Y 

     

  • Verified answer
    Inogic Profile Picture
    703 on at

    As you said you are trying this in a plug-in, we gave you the solution that works with sdk dll's

    But you are using web reference in plugin and here this can be set as follows:

                an.objecttypecode = new EntityNameReference();
                an.objecttypecode.Value = EntityName.account.ToString();
     

    Thanks!

     Sam

  • Prashanth Yerramsetty Profile Picture
    on at

    Hi Sam,

    Thanx,

    It got worked. Thanx for your help.

     

    Regards

    Prashanth Y

     

     

  • Prashanth Yerramsetty Profile Picture
    on at

    Hi Sam,

    The above was working in Visual Studio , but wen i register the plugin and execute it an error is thrown.

     Error Msg: "The object cannot be updated because it is readonly"

    Is there any workaround method to resolve this issue.

    Regards,

    Prasghanth Y.

     

     

  • Inogic Profile Picture
    703 on at

    Hi Prashant,

    On which event of which entity are you writing the code...

    Is there any other code that you have written in the plugin apart from moving the note? Is the entity to which you are moving the note, an inactive record or disabled?

    Sam

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans