Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

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

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

  • Suggested answer
    Pawar Pravin  Profile Picture
    Pawar Pravin 5,227 on at
    RE: Calling a global custom action through javascript and passing input parameters and send email

    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

  • Suggested answer
    Rawish Kumar Profile Picture
    Rawish Kumar 13,756 on at
    RE: Calling a global custom action through javascript and passing input parameters and send email

    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.

  • DineshRaja Profile Picture
    DineshRaja on at
    RE: Calling a global custom action through javascript and passing input parameters and send email

    Am Using D365 V9

  • Suggested answer
    Anas Rafik Profile Picture
    Anas Rafik 361 on at
    RE: Calling a global custom action through javascript and passing input parameters and send email

    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));
    }

  • Verified answer
    AjitPatra Profile Picture
    AjitPatra 469 on at
    RE: Calling a global custom action through javascript and passing input parameters and send email

    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

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,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans