Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/464.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CRM 2011:链接到html页面的javascript webresource在IE11中只加载了几秒钟_Javascript_Jquery_Html_Dynamics Crm 2011_Internet Explorer 11 - Fatal编程技术网

CRM 2011:链接到html页面的javascript webresource在IE11中只加载了几秒钟

CRM 2011:链接到html页面的javascript webresource在IE11中只加载了几秒钟,javascript,jquery,html,dynamics-crm-2011,internet-explorer-11,Javascript,Jquery,Html,Dynamics Crm 2011,Internet Explorer 11,acm\u/membership\u generator\u html.htmcode: <!DOCTYPE html> <html> <head> <title>lidmaatschapgenerator</title> <script src="../ClientGlobalContext.js.aspx"></script> <script type="text/javascr

acm\u/membership\u generator\u html.htm
code:

<!DOCTYPE html>
<html>
<head>
    <title>lidmaatschapgenerator</title>
    <script src="../ClientGlobalContext.js.aspx"></script>
    <script type="text/javascript" src="Scripts/jquery_1.11.1.js"></script>
    <script type="text/javascript" src="Scripts/membership_generation_js.js"></script>
    <link type="text/css" rel="stylesheet" href="Styles/membership_css.css" />
</head>
<body>
    <div id="container">
        <div class="ms-crm-Dialog-Header">
            <div class="ms-crm-Dialog-Header-Title" id="DlgHdTitle">Lidmaatschappen aanmaken</div>
            <div class="ms-crm-Dialog-Header-Desc" id="DlgHdDesc">Maak de persoonlijke lidmaatschappen aan van dit bedrijfslidmaatschap.</div>
        </div>
        <div id="buttons">
            <input type="button" class="ms-crm-Button" id="btnGenerateControls" value="Haal contacten op" />
            <input type="button" class="ms-crm-Button" id="btnCreateMemberships" value="Maak lidmaatschappen aan" />
        </div>
        <div id="ProgressContainer">
            <progress id="barProgress" value="0">
                <label id="ProgressReplacer"></label>
            </progress>
        </div>
        <div id="divCreated"></div>
        <div id="ContactList">
            <div class="ms-crm-FieldLabel-LeftAlign">
                <label>Contacten</label>
            </div>
        </div>
    </div>
</body>
</html>
//CRM entities and records
debugger;
var ODataPath;
var serverUrl;
var EntityId;
var accountId;
var AccountPersonalMembershipList = [];
var AccountContactsList = [];
var CompanyMembershipType = {};
var CompanyMembershipTypeId;
//html controls
var btnCreateMemberships;
var divCreated;
var btnGenerateControls;
var progressBarControl;
var progressBarReplacer;
//binding 
var membershipCount = 0;
var MembershipsCreated = false;

var CheckedBoxesCount = 0;
var ProgressCount = 0;


$(document).ready(function () {
    getDataParam();
    //get context, serverURL and relevant IDs
    var context = GetGlobalContext();
    serverUrl = context.getServerUrl();
    //the CRM 2013 string ends with a slash, we need to trim this;
    serverUrl = serverUrl.replace(/\/$/, "");
    ODataPath = serverUrl + "/XrmServices/2011/OrganizationData.svc";
    //use JQuery to get the relevant controls
    btnCreateMemberships = $("#btnCreateMemberships");
    divCreated = $("#divCreated");
    btnGenerateControls = $("#btnGenerateControls");
    progressBarControl = $("#barProgress");
    progressBarReplacer = $("#ProgressReplacer");
    //get the membership type for the company membership.
    $.when(GetCurrentMemberships(), GetMembershipType(), GetContacts()).done(function () {
        CheckMembershipCount();
    });


    btnGenerateControls.click(function () {
        ProcessContacts(AccountContactsList);
        btnGenerateControls.prop("disabled", true);
        btnGenerateControls.off("click");
    });
    btnCreateMemberships.click(function () {
        CreateMemberships();
    });
});


function getDataParam() {
    //Get the any query string parameters and load them
    //into the vals array

    var vals;
    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'
        for (var i in vals) {
            if (vals[i][0].toLowerCase() == "data") {
                parseDataValue(vals[i][1]);
                return;
            }
        }
    }

}

function parseDataValue(datavalue) {
    if (datavalue != "") {
        var vals = decodeURIComponent(datavalue).split("&");
        for (var i in vals) {
            vals[i] = vals[i].replace(/\+/g, " ").split("=");
        }
        EntityId = vals[0][1];
        accountId = vals[1][1];
        CompanyMembershipTypeId = vals[2][1];
        return;
    }
}

//Retrieve the personal memberships linked to the current company membership;
function GetCurrentMemberships() {
    return $.ajax({
        type: "GET",
        contentType: "application/json; charset=uft-8",
        datatype: "json",
        url: ODataPath + "/acm_lidmaatschappersoonlijkSet?$filter=acm_bedrijfslidmaatschap/Id eq guid'" + EntityId + "'",
        beforeSend: function (xmlHttpRequest) {
            xmlHttpRequest.setRequestHeader("Accept", "application/json");
        },
        success: function (data) {
            AccountPersonalMembershipList = data.d.results;
        },
        error: function () {
            error();
        }
    });
}

//helperfunction to adjust the progress bar
//progress bar is adjusted twice per ajax call.
function add1ToProgress() {
    ProgressCount++;
    progressBarControl.prop("value", ProgressCount);
}

//haal het type bedrijfslidmaatschap op, enkel de velden voor het aantal en soort onderliggende lidmaatschappen.
function GetMembershipType() {
    return $.ajax({
        type: "GET",
        contentType: "application/json; charset=uft-8",
        datatype: "json",
        url: ODataPath + "/acm_lidmaatschapSet(guid'" + CompanyMembershipTypeId + "')?$select=acm_soortonderliggendelidmaatschappen,acm_aantallidmaatschappen",
        beforeSend: function (xmlHttpRequest) {
            xmlHttpRequest.setRequestHeader("Accept", "application/json");
        },
        success: function (data) {
            CompanyMembershipType = data.d;
        },
        error: function () {
            error();
        }
    });
}

//Retrieve all customers linked to the company linked to this membership.
function GetContacts() {
    return $.ajax({
        type: "GET",
        contentType: "application/json; charset=uft-8",
        datatype: "json",
        url: ODataPath + "/ContactSet?$filter=ParentCustomerId/Id eq guid'" + accountId + "'",
        beforeSend: function (xmlHttpRequest) {
            xmlHttpRequest.setRequestHeader("Accept", "application/json");
        },
        success: function (data) {
            AccountContactsList = data.d.results;
        },
        error: function () {
            error();
        }
    });
}

//happens after the above 3 ajax calls are finished;
//checks if the company can make additional memberships
//disables the buttons if this is the case and shows the reason.
function CheckMembershipCount() {
    //check if the company already has the max amount of memberships;
    if (AccountPersonalMembershipList.length >= CompanyMembershipType.acm_aantallidmaatschappen) {
        $("input:button").prop("disabled", true);
        divCreated.append("Dit bedrijf kan geen extra lidmaatschappen meer krijgen omdat het al aan het maximum zit.");
        $("#ProgressContainer").empty();
    } else {
        //check if the company has any contacts that aren't yet members for this company;
        //ContactIsValid returns true if there is any contact that can be made member;
        for (var i in AccountContactsList) {
            if (ContactIsValid(AccountContactsList[i])) {
                return;
            }
        }
        $("input:button").prop("disabled", true);
        divCreated.append("Dit bedrijf heeft geen contacten, of alle gekoppelde contacten hebben reeds een lidmaatschap van dit bedrijf.");
        $("#ProgressContainer").empty();
    }
}

//creates the memberships for the company;
function CreateMemberships() {
    //disable the button so we don't have accidental double commits
    btnCreateMemberships.off("click");
    btnCreateMemberships.prop("disabled", true);
    var createArray = [];
    //get all the checked boxes;
    var checkedBoxes = $(".contactChecks:checked");
    //calculate the amount of checked boxes;
    CheckedBoxesCount = checkedBoxes.size();
    //we want the progress bar to increment once before we start ajaxing and then twice for each ajax (before and after)
    progressBarControl.prop("max", (CheckedBoxesCount * 2) + 1);
    progressBarReplacer.text("0 van " + CheckedBoxesCount);
    //disable the checkboxes so we don't have accidental triggers;
    $(".contactChecks").prop("disabled", true);
    //We want to notify how many memberships have been made after they're all made. since they're async, we'll need to use promises
    //however, because we repeat the same ajax call with different parameters, we need to push them to an array and then apply() them.
    checkedBoxes.each(function () {
        createArray.push(CreateMembershipsAjax(this));
    });
    //we did the work before we start creating them, so show some progress;
    add1ToProgress();
    $.when.apply(null, createArray).done(function () {
        //this function will only start once all ajax calls have been successfull.
        divCreated.append(membershipCount + " lidmaatschappen aangemaakt:");
        MembershipsCreated = true;

    });


}

//if something goes wrong, alert the user;
function error() {
    alert("Er is een fout gebeurd bij het uitvoeren van deze actie. info: ");
}

//add checkboxes for each contact;
function ProcessContacts(result) {
    for (var i in result) {
        var contact = result[i];
        //Check if the contact already exists as a membership for this company.
        if (ContactIsValid(contact)) {
            addCheckBox(contact);
        }
    }
}

function addCheckBox(contact) {
    //get the container to use;
    var container = $("#ContactList");
    //get the contactId;
    var id = contact["ContactId"].toString();
    //create a checkbox
    var checkBox = $(document.createElement('input')).attr({
        id: "cb" + id,
        value: id,
        "class": "contactChecks",
        type: "checkbox",
    });
    //add the onchange to the textbox;
    checkBox.on("change", CheckContactCount);
    //add the container to the checkbox;
    container.append(checkBox);
    //show the name for the contact;
    container.append(contact["FirstName"] + " " + contact["LastName"]);
    //whitespace;
    container.append(
        $(document.createElement("br"))
    );


}

//notifies the user if he tries to select more contacts than can be turned to users;
function CheckContactCount() {
    //calculate the potential memberships, the current memberships and the sum of these 2;
    var checkedCount = $(".contactChecks:checked").size();
    var bestaandLidmaatschapCount = AccountPersonalMembershipList.length;
    var totalCount = checkedCount + bestaandLidmaatschapCount;
    //if the sum is greater than allowed;
    if (totalCount > CompanyMembershipType.acm_aantallidmaatschappen) {
        //show a message to inform
        divCreated.empty();
        divCreated.append("U kunt maximum " + (CompanyMembershipType["acm_aantallidmaatschappen"] - bestaandLidmaatschapCount) + " nieuwe lidmaatschappen maken.");
        divCreated.append(
            $(document.createElement("br"))
        );
        divCreated.append("U heeft nu " + checkedCount + " contacten geselecteerd.");
        //disable the create button;
        btnCreateMemberships.off("click");
        btnCreateMemberships.prop("disabled", true);
    } else {
        //if the sum not greater;
        //empty the creation message;
        divCreated.empty();
        //rebind the button, unbinding previous ones in the process;
        //We don't need to worry about accidentally rebinding the button when it's disabled:
        //Either we disabled through this function, so it's reversing itself;
        //or it was disabled through clicking the button, which disables these checkboxes anyway.
        btnCreateMemberships.off("click");
        btnCreateMemberships.click(function () {
            CreateMemberships();
        });
        btnCreateMemberships.prop("disabled", false);
    }
}

function ContactIsValid(contact) {
    for (var i in AccountPersonalMembershipList) {
        //localeCompare returns 0 if the strings are equal, so need to invert for a boolean
        if (!AccountPersonalMembershipList[i]["acm_contactpersoon"].Id.localeCompare(contact["ContactId"])) {
            //if it's equal, it returns false because the contact already has a membership with this company
            return false;
        }
    }
    //if no memberships with this name are found, it should return true so the Contact is valid for showing.
    //still need to check if there's not yet a control with with that id as a value.
    //get all checkboxes with this ContactId
    var checkboxes = $(":checkbox[value=" + contact["ContactId"] + "]");
    //if any exist
    if (checkboxes.length > 0) {
        //return false
        return false;
    }
    return true;
}

function CreateMembershipsAjax(element) {
    var contactId = element.defaultValue;
    //create the membership
    var persoonlijkLidmaatschap = new Object();
    persoonlijkLidmaatschap.acm_contactpersoon = { Id: contactId.replace(/[{}]/g, "") };
    persoonlijkLidmaatschap.acm_bedrijfslidmaatschap = { Id: EntityId.replace(/[{}]/g, "") };
    persoonlijkLidmaatschap.acm_lidmaatschap = { Id: CompanyMembershipType.acm_soortonderliggendelidmaatschappen.Id.replace(/[{}]/g, "") };
    //turn the json into a string using default browser set;
    var lidmaatschapJson = JSON.stringify(persoonlijkLidmaatschap);
    //increment the counter once before the ajax call;
    add1ToProgress();
    return $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        url: ODataPath + "/acm_lidmaatschappersoonlijkSet",
        data: lidmaatschapJson,
        beforeSend: function (xmlHttpRequest) {
            xmlHttpRequest.setRequestHeader("Accept", "application/json");
        },
        success: function () {
            //increment the counter again after the ajax call;
            membershipCount++;
            add1ToProgress();
            progressBarReplacer.text(membershipCount + " van " + CheckedBoxesCount + "memberships aangemaakt.");
        },
        error: function () {
            error();
        }
    });
}
加载html页面的方法(作为功能区按钮上的javascript操作添加):

这段代码在Chrome中运行良好。然而,在IE11中,html webresource被打开,Jquery被加载,CSS和ClientContext被加载,但是上面的javascript代码加载了几秒钟(使用F12工具检查),但几秒钟后,它从工具中的我的资源列表中消失。我在我的错误日志中还收到一条消息:“Id、某物或预期的其他东西”(对其他2项不太确定):


我不知道这是什么原因。它在Chrome中工作良好,但在IE11中则不行。这只是一些基于一些CRM数据动态生成控件的代码,我不知道为什么它在一个浏览器中失败,但在另一个浏览器中失败。

我发现了导致这种情况的原因,而且一如既往,它非常小

IE11抱怨属性数组末尾的逗号。我去掉了它,它就起作用了

function acm_mscrm2011_openModalDialog() {
    var entityId = Xrm.Page.data.entity.getId();
    var accountId = Xrm.Page.getAttribute("acm_account").getValue()[0].id;
    var companyMembershipTypeId = Xrm.Page.getAttribute("acm_typelidmaatschap").getValue()[0].id;
    var parameters = encodeURIComponent("entityId=" + entityId + "&accountId=" + accountId + "&membershiptype=" + companyMembershipTypeId);
    Xrm.Utility.openWebResource("acm_/membership_generator_html.htm", parameters);
}
var checkBox = $(document.createElement('input')).attr({
        id: "cb" + id,
        value: id,
        "class": "contactChecks",
        type: "checkbox",
    });