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 :
Microsoft Dynamics CRM (Archived)

how to create the task of the opportunity using the javascript

(0) ShareShare
ReportReport
Posted on by 232

how we can create the task in the opportunity using the javascript

*This post is locked for comments

I have the same question (0)
  • Karsten Wirl Profile Picture
    4,477 on at

    Hi there.

    Please can you specify your issue? I'm not sure if I understood your requirements correctly.

    Kind regards,

    Karsten

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

    if you want to create a task with Javascript you will need to use the WebAPI. In order to easily create your request, you should take a look at the CRMRESTBuilder: github.com/.../CRMRESTBuilder

  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    Something like this should work:

    var entity = {};

    entity.subject = "Test";

    entity["regardingobjectid_opportunity@odata.bind"] = "/opportunities(12345678-1234-1234-1234-1234567890AB)";

    var req = new XMLHttpRequest();

    req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v8.0/tasks", true);

    req.setRequestHeader("OData-MaxVersion", "4.0");

    req.setRequestHeader("OData-Version", "4.0");

    req.setRequestHeader("Accept", "application/json");

    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");

    req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");

    req.onreadystatechange = function() {

       if (this.readyState === 4) {

           req.onreadystatechange = null;

           if (this.status === 204) {

               Xrm.Utility.alertDialog("New Task Record Created with Related Opportunity");

           } else {

               Xrm.Utility.alertDialog(this.statusText);

           }

       }

    };

    req.send(JSON.stringify(entity));

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans