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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

C# ActivityPointer StateCode Update

(0) ShareShare
ReportReport
Posted on by

Hi All,

I'm try to update the statecode of the activitypointer entity through C# code but I'm having some issues doing so. I'm using the below code to do so,

UpdateStateValueRequest updateStateValue = new UpdateStateValueRequest
{
AttributeLogicalName = "statecode",
EntityLogicalName = "activitypointer",
Value = 1, //Completed
};

service.Execute(updateStateValue);

 

service is OrganizationServiceProxy and is already connected in a using statement further up in the code.

 

The code does not return any errors when this is executed which make me believe that is working. If I look in the UI or the database the statecode is still not updating. The only thing I can't understand about the above code snippet, there is not way that is linking to the specific activity.

 

Any ideas of what I have done wrong or any ways of completing this task would be greatly apprecaited.

Thanks.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

    The code you have written is for updating the Metadata of option set i.e. changing the

    label of existing option.

    But you have not passed new value in the field and that might be the issue.

    In case you want to update a specific records value and change state for that you can use SetState request.

    msdn.microsoft.com/.../microsoft.crm.sdk.messages.setstaterequest.aspx

    Thanks,

    Abhinav Ranjan.

  • Community Member Profile Picture
    on at

    Thanks Abhinav. I have tried suggested link and it might not work with the entity as this the activitypointer. This is the code snippet that I tried.

    SetStateRequest state = new SetStateRequest();

    state.State = new OptionSetValue(1); // Complete

    state.Status = new OptionSetValue(2);  // Complete

    state.EntityMoniker = new EntityReference("activitypointer", activityId);

    SetStateResponse stateSet = (SetStateResponse)service.Execute(state);

    It returns the below error message, when I try to execute the code.

    Error Message - The 'SetStateDynamicEntity' method does not support entities of type 'activitypointer'.

    Is the statecode update on the 'activitypointer' entity done in another way?

  • Verified answer
    Community Member Profile Picture
    on at

    Hi,

    My bad for not paying attention and mentioning earlier.

    From ActivityPointer you need to get related Activity object and set state for that.

    ActivityPointer object will contain the "ActivityTypeCode" and "ActivityId"

    You can create EntityReference from that and set the state.

    A rough idea for that:

    EntityReference etyRef = new EntityReference();

    etyRef.LogicalName = actPointer.ActivityTypeCode;

    etyRef.Id = actPointer.ActivityId;

    Now use this object (etyRef ) to set state.

    Thanks,

    Abhinav Ranjan

  • waghmare pallavi Profile Picture
    on at

    Hi Abhinav Ranjan

    I am Also Facing The Same Issue ,in my code am trying to Mark all Activity as Completed.

    I have written Code For  Plugin. a PostCreate Plugin On My custom entity.

    here is my Code 

    SetStateRequest SetStateReq = new SetStateRequest();

    SetStateReq.EntityMoniker = new EntityReference(sEntityLogicalName, gActivityId);

    if (sEntityLogicalName.Contains("Phone Call"))

    {
    // Set the State and Status OptionSet Values to completed.
    SetStateReq.State = new OptionSetValue((int)PC.Enum.ActivityStateCode.Completed);
    SetStateReq.Status = new OptionSetValue((int)PC.Enum.PhoneCallActivityStatusCode.Made);
    }

    SetStateResponse _SetStateResp = (SetStateResponse)organizationService.Execute(SetStateReq);

    But the above Code  throw an Exception Required State Field Is Missing.

    Regards

    Pallavi Waghmare 

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans