Notifications
Announcements
No record found.
how we can create the task in the opportunity using the javascript
*This post is locked for comments
Hi there.
Please can you specify your issue? I'm not sure if I understood your requirements correctly.
Kind regards,
Karsten
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
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
SA-08121319-0 4
Calum MacFarlane 4
Alex Fun Wei Jie 2