Open WebResource passing the parameters in mscrm

/////////////// open WebResource passing the parameters////////////
function OpenCreditCardDlg() {
    debugger;
    var params = new Object();
    var salesEntityName;
    var salesEntityId;
    var amount;
    if (Xrm.Page.data.entity.getEntityName() == "invoice" || Xrm.Page.data.entity.getEntityName() == "salesorder" || Xrm.Page.data.entity.getEntityName() == "opportunity" || Xrm.Page.data.entity.getEntityName() == "quote") {
        salesEntityName = Xrm.Page.data.entity.getEntityName();
        salesEntityId = Xrm.Page.data.entity.getId();

        if (Xrm.Page.getAttribute("totalamount") != null && Xrm.Page.getAttribute("totalamount").getValue() != null) {
            amount = Xrm.Page.getAttribute("totalamount").getValue();
        }

        if (Xrm.Page.getAttribute("customerid") !== null && Xrm.Page.getAttribute("customerid").getValue() !== null) {
            if (Xrm.Page.getAttribute("customerid").getValue()[0].entityType === "contact") {
                param = encodeURIComponent("recId=" + Xrm.Page.getAttribute("customerid").getValue()[0].id + "&fullName=" + Xrm.Page.getAttribute("customerid").getValue()[0].name + "&custEntity=" + Xrm.Page.getAttribute("customerid").getValue()[0].entityType + "&orderAmount=" + amount + "&salesEntityName=" + salesEntityName + "&salesEntityId=" + salesEntityId + "");
            }
            if (Xrm.Page.getAttribute("customerid").getValue()[0].entityType === "account") {
                param = encodeURIComponent("recId=" + Xrm.Page.getAttribute("customerid").getValue()[0].id + "&fullName=" + Xrm.Page.getAttribute("customerid").getValue()[0].name + "&custEntity=" + Xrm.Page.getAttribute("customerid").getValue()[0].entityType + "&orderAmount=" + amount + "&salesEntityName=" + salesEntityName + "&salesEntityId=" + salesEntityId + "");
            }
        }
        if (typeof (param) != 'undefined' && param != null) {
            Xrm.Utility.openWebResource("apy_CreditCardTransaction.html", param, 450, 600);
        }
    }
}
$(document).ready(function () {
    //show the loading pannel div/image
    showLoadingMessage_Process();
    //hide the loading pannel div/image
    $('#msgDiv').hide();
    var xrmObject = getDataParam();
    //   var cardType = null, authDuration = null, ccAmount = null, orderAmount = null;
    //   var contactFullName = xrmObject.fullName;
    //   contactId = xrmObject.recId;
    //   order = xrmObject.orederRec;
    //   invoice = xrmObject.invoiceRec;
    //   orderAmount = xrmObject.orderAmount;
    //   customerEntity = xrmObject.custEntity;
    //   opportunity = xrmObject.opportunityRec;
    //quote = xrmObject.quoteRec;

    contactId = xrmObject == null ? null : xrmObject[0][1];
    var contactFullName = xrmObject == null ? null : xrmObject[1][1];
    customerEntity = xrmObject == null ? null : xrmObject[2][1];
    orderAmount = xrmObject == null ? null : xrmObject[3][1];
    salesEntityName = xrmObject == null ? null : xrmObject[4][1];
    salesEntityId = xrmObject == null ? null : xrmObject[5][1];
},
function getDataParam() {
    //Get the any query string parameters and load them
    //into the vals array
    var object = null;
    var vals = new Array();
    if (location.search != "") {
        vals = location.search.substr(1).split("&");
        for (var i in vals) {
            vals[i] = vals[i].replace(/\+/g, " ").split("=");
        }
        //look for the parameter named 'data'
        var found = false;
        for (var i in vals) {
            if (vals[i][0].toLowerCase() == "data") {
                object = parseDataValue(vals[i][1]);
                found = true;
                break;
            }
        }
        if (!found)
        { noParams(); }
    }
    else {
        noParams();
    }
    return object;
}

function parseDataValue(datavalue) {
    var vals = null;
    if (datavalue != "") {
        vals = new Array();
        vals = decodeURIComponent(datavalue).split("&");
        for (var i in vals) {
            vals[i] = vals[i].replace(/\+/g, " ").split("=");
        }
    }
    return vals;
}

function showLoadingMessage_Process() {
    var LoadingHTML = "<div align='center' id='msgDiv' style='background:#FFFFFF; font-size:15px; vertical-align:middle; z-index:1010; width:100%; height:100%; left:0px; top:5px; position:absolute;'><table style='left: 50%; top: 35%; width: 100px; height: 100px; position: absolute; cursor: wait;'><tbody><tr><td style='padding-top: 35%;' vAlign='' align='center'><img alt='' src='/_imgs/AdvFind/progress.gif'><div><b>Working...</b></div></td></tr></tbody></table></div>";
    $(LoadingHTML).prependTo("body");
}

Comments

Popular posts from this blog

Basic Plugin Code in D365 using C#

CURD (Create, Update, Retrieve and Delete) Operation in D365 using Power Shell Script

Meta Data Using WebApiRequest