moussa-e
5/8/2017 - 11:23 AM

XrmServiceToolkit #Dynamics365 #XrmServiceToolkit #Javascript

XrmServiceToolkit #Dynamics365 #XrmServiceToolkit #Javascript

function Retrieve() {
    var re, entityId;
    XrmServiceToolkit.Rest.Retrieve(
        entityId,
        "AccountSet",
        null, null,
        function(result) {
            re = result;
            alert("success");
        },
        function(error) {
            alert("failed");
        },
        false
    );
    //debugger;
    alert(re.Name);
    alert(re.AccountId);
}

function Delete() {
    var entityId;
    XrmServiceToolkit.Rest.Delete(
        entityId,
        "AccountSet",
        function() {
            alert("successfully deleted");
        },
        function(error) {
            alert("failed to delete");
        },
        false
    );
}

function Update() {
    var entityId;
    var account = {};
    account.Name = "SO and Company A1";
    account.Address1_AddressTypeCode = {
        Value: 3
    }; //Address 1: Address Type = Primary
    account.Address1_City = "Wentworthville";
    account.Address1_Line1 = "153 Dunmore Stret";

    XrmServiceToolkit.Rest.Update(
        entityId,
        account,
        "AccountSet",
        function() {
            alert("successfully Updated");
        },
        function(error) {
            alert("failed to Update");
        },
        false
    )
}

function Create() {
    var account = {};
    account.Name = "SO and Company B1";
    account.Address1_AddressTypeCode = {
        Value: 3
    }; //Address 1: Address Type = Primary
    account.Address1_City = "Wentworthville B";
    account.Address1_Line1 = "153 Dunmore Stret B";

    XrmServiceToolkit.Rest.Create(
        account,
        "AccountSet",
        function(result) {
            accountId = result.AccountId;
            alert("successfully Created. Acc ID : " + result.AccountId);
        },
        function(error) {
            alert("failed to Create Account");
        },
        false
    );
}

XrmServiceToolkit.Rest.Associate(
    contactId,
    "ContactSet",
    accountId,
    "AccountSet",
    "account_primary_contact",
    function () {
        equals(true, true, "The record should have been associated.");
    },
    function (error) {
        equal(true, false, error.message);
    },
    false
);

XrmServiceToolkit.Rest.Disassociate(
        contactId,
        "ContactSet",
        accountId,
        "account_primary_contact",
        function () {
            equals(true, true, "The record should have been disassociated.");
        },
        function (error) {
            equal(true, false, error.message);
        },
        false
    );