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 :
Customer experience | Sales, Customer Insights,...
Answered

How to set Activity statecode and statusCode on creartion?

(0) ShareShare
ReportReport
Posted on by 5

Hello all,

I'm having troubles while creating new task activity and marking it as completed.

I'm creating tasks easily but I want to set them to Complete while creating them.

So I send this object.

var testtt = new test
                {
                    description = "test task description",
                    subject = "test Hima 14",
                    scheduledstart = new DateTime(2020, 4, 1, 12, 0, 0),
                    scheduledend = new DateTime(2020, 4, 1, 15, 0, 0),
                    regardingobjectid_lead = "/leads(6329dbd0-4e1c-e511-80d3-3863bb347ba8)",
                    statuscode = 2,
                    statecode = 1
 
                };

I just don't know what is wrong, I googled a lot for statecode and statuscode values and I think I set them correctly.

I referenced this thread but with no luck at all https://community.dynamics.com/crm/f/microsoft-dynamics-crm-forum/253880/change-the-state-and-status-reason-through-web-api

Thanks in advance

I have the same question (0)
  • Marco.P Profile Picture
    2,405 on at

    Hi,

    To set the status, i think you should use the set state request

    Please refer to official MS doc:

    docs.microsoft.com/.../microsoft.crm.sdk.messages.setstaterequest

    Hope it helps,

    Marco

  • ibrahim_Hasan Profile Picture
    5 on at

    Hi marco, and thanks for your response.

    I'm using restful web apis so is there any URI I can use as i'm not using the crm sdk

    I referenced this thread but with no luck at all https://community.dynamics.com/crm/f/microsoft-dynamics-crm-forum/253880/change-the-state-and-status-reason-through-web-api

  • Marco.P Profile Picture
    2,405 on at

    Hi Ibrahim,

    My bad. Try to build your call using CRM rest builder.

    github.com/.../CRMRESTBuilder

  • Verified answer
    Marco.P Profile Picture
    2,405 on at

    I don't think it will be possible to create a "disabled" record. I've just tried and it throw me an error (statuscode invalid).

    I make it work this way:

    var entity = {};

    entity.description = "test";

    entity.subject = "test dynamics";

    entity.scheduledstart = new Date("04/04/2020 03:30:00").toISOString();

    entity.scheduledend = new Date("04/04/2020 05:30:00").toISOString();

    entity["regardingobjectid@odata.bind"] = "/leads(yourrecordguid)";

    Xrm.WebApi.online.createRecord("task", entity).then(

       function success(result) {

         entity.statuscode = 5;

    entity.statecode = 1;

           Xrm.WebApi.online.updateRecord("task", result.id, entity)

       },

       function(error) {

           Xrm.Utility.alertDialog(error.message);

       }

    );

    Hope it helps,

    Marco

  • ibrahim_Hasan Profile Picture
    5 on at

    Thanks That worked for me also.

    For anyone using restful api just make sure that you are sending PATCH request not PUT.

    and send the right statuscode and statecode

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 108 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans