Curd Operations Using XrmSvcToolkit

/////////////CURD Operation Using XrmSvcToolkit////////////////////////////

var entity = {};
entity.new_Currency = { Value: parseFloat(123).toFixed(4) };
entity.new_Customer = {
    Id: "123456789",
    LogicalName: "account"
};
entity.new_DataandTime = new Date("10/18/2017").toLocaleString();
entity.new_DecimalNumber = parseFloat(12323).toFixed(2);
entity.new_FloatPointNumber = parseFloat(2321.44).toFixed(2);
entity.new_Lookup = {
    Id: "1234567",
    LogicalName: "account"
};
entity.new_MultiLineTextBox = "test";
entity.new_OptionSet = { Value: 1 };
entity.new_SIngleLineTExt = "testing";
entity.new_TwoOption = false;
entity.new_WholeNumber = 123;

XrmSvcToolkit.createRecord({
    entityName: "Account",
    entity: entity,
    async: false,
    successCallback: function (result) {
        var newEntityId = result.AccountId;
    },
    errorCallback: function (error) {
        alert(error.message);
    }
});


var entity = {};
entity.new_Currency = { Value: parseFloat(123).toFixed(4) };
entity.new_Customer = {
    Id: "123456",
    LogicalName: "account"
};
entity.new_DataandTime = new Date("10/19/2017").toLocaleString();
entity.new_DecimalNumber = parseFloat(123).toFixed(2);
entity.new_FloatPointNumber = parseFloat(323.32).toFixed(2);
entity.new_Lookup = {
    Id: "2134567533",
    LogicalName: "account"
};
entity.new_MultiLineTextBox = "text";
entity.new_OptionSet = { Value: 2 };
entity.new_SIngleLineTExt = "text single line";
entity.new_TwoOption = false;
entity.new_WholeNumber = 21423;

XrmSvcToolkit.updateRecord({
    entityName: "Account",
    id: "",
    entity: entity,
    async: false,
    successCallback: function () {
        alert("Updated"); //Success - No Return Data - Do Something
    },
    errorCallback: function (error) {
        alert(error.message);
    },
});

XrmSvcToolkit.deleteRecord({
    entityName: "Account",
    id: "1234567",
    async: false,
    successCallback: function () {
        alert("Deleted"); //Success - No Return Data - Do Something
    },
    errorCallback: function (error) {
        alert(error.message);
    }
});

XrmSvcToolkit.retrieve({
    entityName: "Account",
    id: "1234343554544456",
    select: ["new_Currency", "new_Customer", "new_DataandTime", "new_DecimalNumber", "new_FloatPointNumber", "new_Lookup", "new_MultiLineTextBox", "new_OptionSet", "new_SIngleLineTExt", "new_TwoOption", "new_WholeNumber"],
    expand: ['user_accounts'],
    async: false,
    successCallback: function (result) {
        var new_Currency = result.new_Currency;
        var new_Customer = result.new_Customer;
        var new_DataandTime = result.new_DataandTime;
        var new_DecimalNumber = result.new_DecimalNumber;
        var new_FloatPointNumber = result.new_FloatPointNumber;
        var new_Lookup = result.new_Lookup;
        var new_MultiLineTextBox = result.new_MultiLineTextBox;
        var new_OptionSet = result.new_OptionSet;
        var new_SIngleLineTExt = result.new_SIngleLineTExt;
        var new_TwoOption = result.new_TwoOption;
        var new_WholeNumber = result.new_WholeNumber;
    },
    errorCallback: function (error) {
        alert(error.message);
    }
});

XrmSvcToolkit.retrieveMultiple({
    entityName: "Account",
    odataQuery: "?$select=new_Currency,new_Customer,new_DataandTime,new_DecimalNumber,new_FloatPointNumber,new_Lookup,new_MultiLineTextBox,new_OptionSet,new_SIngleLineTExt,new_TwoOption,new_WholeNumber&$top=10000",
    async: false,
    successCallback: function (results) {
        for (var i = 0; i < results.length; i++) {
            var new_Currency = results[i].new_Currency;
            var new_Customer = results[i].new_Customer;
            var new_DataandTime = results[i].new_DataandTime;
            var new_DecimalNumber = results[i].new_DecimalNumber;
            var new_FloatPointNumber = results[i].new_FloatPointNumber;
            var new_Lookup = results[i].new_Lookup;
            var new_MultiLineTextBox = results[i].new_MultiLineTextBox;
            var new_OptionSet = results[i].new_OptionSet;
            var new_SIngleLineTExt = results[i].new_SIngleLineTExt;
            var new_TwoOption = results[i].new_TwoOption;
            var new_WholeNumber = results[i].new_WholeNumber;
        }
    },
    errorCallback: function (error) {
        alert(error.message);
    }
});

XrmSvcToolkit.associate({
    entity1Name: "Account",
    entity1Id: "121323443454565667",
    entity2Name: "Task",
    entity2Id: "65444332421321",
    relationshipName: "",
    async: false,
    successCallback: function () {
        alert("Associated"); //Success - No Return Data - Do Something
    },
    errorCallback: function (error) {
        alert(error.message);
    }
});

XrmSvcToolkit.disassociate({
    entity1Name: "Account",
    entity1Id: "121323443454565667",
    entity2Name: "Task",
    entity2Id: "65444332421321",
    relationshipName: "",
    async: false,
    successCallback: function () {
        alert("Disassociated"); //Success - No Return Data - Do Something
    },
    errorCallback: function (error) {
        alert(error.message);
    }
});

Comments

Popular posts from this blog

Meta Data Using WebApiRequest

Sample CRUD Operations Using C# in MSCRM

Basic Plugin Code in D365 using C#