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)

Calling a global custom action through javascript and passing input parameters and send email

(0) ShareShare
ReportReport
Posted on by

Hi Guys,

I created one custom entity in that custom entity i have a ribbon while click the button javascript is called,In the javascript i add the custom action for send the email..i don't know where i made mistake..help me guys..this is my code

function sendAction() {

var Id = Xrm.Page.data.entity.getId().replace('{', '').replace('}', '');


var serverURL = Xrm.Page.context.getClientUrl();

// pass the id as input parameter
var data = {

"Description" : "CRM Meeting",
"Subject" : "Invoking from Web API"
};

var query = "new_receptionmanagementsystems(" +Id+ ")/Microsoft.Dynamics.CRM.new_ActionforReceptionManagementSystem";

var req = new XMLHttpRequest();

// specify name of the entity, record id and name of the action in the Wen API Url
req.open("POST", serverURL + "/api/data/v8.0/" + query, true);

req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.onreadystatechange = function () {
if (this.readyState == 4 /* complete */) {
req.onreadystatechange = null;
if (this.status == 200) {
var data = JSON.parse(this.response);
alert(data);
} else {
var error = JSON.parse(this.response).error;
alert(error.message);
}
}
};

// send the request with the data for the input parameter
req.send(window.JSON.stringify(data));
}

Thank You

*This post is locked for comments

I have the same question (0)
  • Verified answer
    AjitPatra Profile Picture
    469 on at

    Hi Dinesh,

    Which D365 version you are using? If you are using D365 V9, then Xrm.Page library has been deprecated. You need to pass PrimaryControl as first CRM parameter from Ribbon Workbench, then pass it to the JS function. At client side you need to use formContext.data.entity instead of Xrm.Page.data.entity and Xrm.Utility.getGlobalContext().getClientUrl() instead of  Xrm.Page.context.getClientUrl().

    Please refer below links:

    Ribbon button and corresponding client side code changes: ajitpatra.com/.../d365-v9upgrade-ribbon-button-changes

    Calling Action with Input parameters from JS: ajitpatra.com/.../d365-v9upgrade-sharing-record-using-web-api-and-custom-action

    Thanks,

    Ajit

  • Suggested answer
    Anas Rafik Profile Picture
    365 on at

    try this

    function sendAction() {
    
        var Id = Xrm.Page.data.entity.getId().replace('{', '').replace('}', '');
    
    
        var serverURL = Xrm.Page.context.getClientUrl();
    
        // pass the id as input parameter
        var data = {
    
            "Description": "CRM Meeting",
            "Subject": "Invoking from Web API"
        };
    
        var query = "new_receptionmanagementsystems(" + Id + ")/Microsoft.Dynamics.CRM.new_ActionforReceptionManagementSystem";
    
        var req = new XMLHttpRequest();
    
        // specify name of the entity, record id and name of the action in the Wen API Url
        req.open("POST", serverURL + "/api/data/v8.0/" + query, false);
    
        req.setRequestHeader("Accept", "application/json");
        req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        req.setRequestHeader("OData-MaxVersion", "4.0");
        req.setRequestHeader("OData-Version", "4.0");
        req.onreadystatechange = function() {
            if (this.readyState == 4 /* complete */ ) {
                req.onreadystatechange = null;
                if (req.status == 200) {
                    var data = JSON.parse(req.response);
                    alert(data);
                } else {
                    var error = JSON.parse(req.response).error;
                    alert(error.message);
                }
            }
        };

        // send the request with the data for the input parameter
        req.send(window.JSON.stringify(data));
    }

  • DineshRaja Profile Picture
    on at

    Am Using D365 V9

  • Suggested answer
    Rawish Kumar Profile Picture
    13,758 on at

    Hi There,

    few things:

    1. if you dont know where it is failing - the best to know is debug the java script in your browser and know the culprit line.

    2. As you said you are on V9 and as Ajit mentioned above the Xrm.Page is deprecated you should start using form context rather.

  • Suggested answer
    Pawar Pravin  Profile Picture
    5,237 on at

    Hi Dinesh,

    If you have a CRM Rest builder solution in your CRM then you can use Execute Action option to check if it is working or not.

    Also please do use latest js library to execute action.

    www.inogic.com/.../execute-global-action-in-dynamics-365-v9-0-usingxrm-utility-invokeprocessaction

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