Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

How to set Activity statecode and statusCode on creartion?

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

  • ibrahim_Hasan Profile Picture
    ibrahim_Hasan 5 on at
    RE: How to set Activity statecode and statusCode on creartion?

    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

  • Verified answer
    Marco.P Profile Picture
    Marco.P 2,405 on at
    RE: How to set Activity statecode and statusCode on creartion?

    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

  • Marco.P Profile Picture
    Marco.P 2,405 on at
    RE: How to set Activity statecode and statusCode on creartion?

    Hi Ibrahim,

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

    github.com/.../CRMRESTBuilder

  • ibrahim_Hasan Profile Picture
    ibrahim_Hasan 5 on at
    RE: How to set Activity statecode and statusCode on creartion?

    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
    Marco.P 2,405 on at
    RE: How to set Activity statecode and statusCode on creartion?

    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

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 Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans