Skip to main content

Notifications

Announcements

No record found.

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

  • shoaib.11 Profile Picture
    shoaib.11 10 on at
    RE: How to Set Lookup value using Plugin

    Thanks For Suggestion

  • Saddamk206 Profile Picture
    Saddamk206 777 on at
    RE: How to Set Lookup value using Plugin

    Get Value of Lookup fields

    EntityReference entref = (EntityReference)item.Attributes[attributeName];

    var LookupId = entref.Id;

    var logicalName = entref.LogicalName;

    Set Value of Lookup fields

    newAccount[attributeName] = new EntityReference(logicalName, LookupId);

    Set Null Value of Lookup fields

    newAccount[attributeName] = Null;

  • Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: How to Set Lookup value using Plugin

    Hi Sam,

    I have an Custom Entity "new_Leadlist"

    When i update Phone call status as "Call Succeeded" a new Leadlist record gets created. I used javascript to create this record.

    In this new_leadlist entity Create event i registered Plugin which checks for any attachments for PhoneCall, if attachments are present those attachments will get attached to Leadlist record which got created.

    For moving attachments from Phonecall to Leadlist i am updating objectId column in annotationbase table.

    This objectid contains Phonecall Guid now i am updating with Leadlist GUID

    Plugin is getting triggered but showing Eror "The object Cannot be Updated because it is readonly"

    The same i tried with Javascript to update the column faced the same error.

    Regards,

    Prashanth Y. 

     

  • Inogic Profile Picture
    Inogic 24,102 on at
    Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: How to Set Lookup value using Plugin

    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

  • Re: Re: Re: Re: Re: Re: Re: Re: Re: How to Set Lookup value using Plugin

    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.

     

     

  • Re: Re: Re: Re: Re: Re: Re: Re: How to Set Lookup value using Plugin

    Hi Sam,

    Thanx,

    It got worked. Thanx for your help.

     

    Regards

    Prashanth Y

     

     

  • Verified answer
    Inogic Profile Picture
    Inogic 24,102 on at
    Re: Re: Re: Re: Re: Re: Re: How to Set Lookup value using Plugin

    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

  • Re: Re: Re: Re: Re: Re: How to Set Lookup value using Plugin

    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 

     

  • Inogic Profile Picture
    Inogic 24,102 on at
    Re: Re: Re: Re: Re: How to Set Lookup value using Plugin

    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

  • Re: Re: Re: Re: How to Set Lookup value using Plugin

    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 

     

     

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,391 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans