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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

About updating case id by plugin

(0) ShareShare
ReportReport
Posted on by

Hi all,

there's a requirement I need to create a synchronous pre create plugin on CASE entity to update the CASE ID field,

but I found it doesn't work when I directly set value by using the 'Target' entity:

Entity entity = (Entity)context.InputParameters["Target"];
entity['field'] = myValue;

However, I need to new another case entity, write some code like:

Entity entity = (Entity)context.InputParameters["Target"];
Entity newcase = new Entity('incident');
newcase.id = entity.id;  //?
entity['filed'] = myValue;

then the case id could be updated successfully.  I wanna know why it doesn't work with the first way.

If there's any information unclear, please let me know.

Thanks.

*This post is locked for comments

I have the same question (0)
  • gdas Profile Picture
    50,091 Moderator on at
    RE: About updating case id by plugin

    Hi ,

    Could you please share the  error you are getting for the first code , seems the attribute not getting for the first scenario. Try to debug the code and also add below line before update the field.

                                if (entity.Attributes.Contains("fieldName"))
                                {
    }


  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at
    RE: About updating case id by plugin

    You can also look for similar post here, this should help you :www.cloudfronts.com/custom-auto-number-for-cases if still facing issue share your code here.

  • Community Member Profile Picture
    on at
    RE: About updating case id by plugin

    Hi Goutam,

    there'e no error actually, just no update on CASE ID field.  Thanks.

  • Felippe Profile Picture
    796 on at
    RE: About updating case id by plugin

    Sorry, Why do you need to update the GUID or set a specific GUID for a new Record?

    The  Create method will return the Guid after the creation of the record and them you can do what do you want with the fields.

    Best regards,

  • Suggested answer
    BadrinathB Profile Picture
    970 on at
    RE: About updating case id by plugin

    Hi Yvonne,

    You can try the below link. I am not sure if you are trying to update the Guid. That is not recommended.

    entity.Attributes.Add('filed',value);

    Attribute might not be present in your target.

  • Community Member Profile Picture
    on at
    RE: About updating case id by plugin

    Hi Mahen,

    I had followed the link you gave above, and I noticed it uses the same way I mentioned on my post(new another entity and set entity Id):

    //// Case Number update

             Entity caserecord = new Entity("incident");

             caserecord.Id = casenumber.Id;

             casenumber["ticketnumber"] = caseNumber;

    This is what I wanna know why I can't set value directly by using entity 'Target' and must new another entity.  Thanks.

  • David Jennaway Profile Picture
    14,065 on at
    RE: About updating case id by plugin

    Can you clarify which stage the plugin runs on ? In the initial question you say it is pre-create, but you won't have the .Id property at this point, as it is only generated when the record is saved.

    I suspect that your plugin is registered on the post step, as then you will have the .Id available, but also changes to the Target input parameter are not stored. If the plugin is registered on the pre step, then changes to the Target input parameter should work

  • Suggested answer
    Shidin Haridas Profile Picture
    3,497 on at
    RE: About updating case id by plugin

    Try add the ID property in the PreOperation plugin step (and not the PreValidation step.)

  • Suggested answer
    Kalp Shah Profile Picture
    35 on at
    RE: About updating case id by plugin

    Hi, Please use below code.

    Entity entity = (Entity)context.InputParameters["Target"];
    
    tracingService.Trace("GUID: "   entity.Id   " Logical Name: "   entity.LogicalName);
    
    if (entity.Attributes.Contains("subjectid"))
    
    {
    
    EntityReference subjectRefernce = (EntityReference)entity.Attributes["subjectid"];
    
    if (subjectRefernce != null)
    
    {
    
    var subjectAttribute = service.Retrieve("subject", subjectRefernce.Id, new ColumnSet("title"));
    
    var title = subjectAttribute.Attributes["title"];
    
    tracingService.Trace("Title : "   title);
    if (title != null)
    
    entity["ticketnumber"]  = "-"   title;
    
    }
    
    }
    
    tracingService.Trace("Case number updated successfully: "   entity["ticketnumber"]);

    Note: Make sure your plugin is in pre-operation method.

    If found useful, please mark the answer as verified

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#2
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans