Ascentium CrmService JavaScript Library

by Ercan Tüzün 11/7/2008 5:11:00 PM

Yazılım geliştiricilere CRM platformu üzerinde kolaylık sağlayacak bir javascript library si ve kullanım örnekleri.Aşağıda kaynağın linkini ve library i indirebiliceğiniz linkleri bulabilirsiniz.

 

Ascentium CrmService Samples

The CrmService.js script supports sending messages directly to the CRM 4.0 web service utilizing only JavaScript. You can use this file in your own ASPX pages, from with CRM forms or virtually anywhere.

The following methods are supported:

  • Create
  • Retrieve
  • Update
  • Delete
  • Fetch
  • Associate
  • Disassociate
  • SetState

For many of the of these you can also pass in a callback function so they can execute asynchronously.

Create, Retrieve, Update, Delete Sample

This sample shows how to Create, Retrieve, Update and Delete records within CRM. Notice when creating the Contact that to set the parentcustomerid there is a special CrmLookup object you need to use. Use this for all lookups.

function Run()
{
    //create the Ascentium_CrmService object
    var oService = new Ascentium_CrmService("MicrosoftCrm", "http://localhost:5555");

    //create an entity
    var beAccount = new BusinessEntity("account");
    beAccount.attributes["name"] = "Ascentium";
    beAccount.attributes["numberofemployees"] = 600.00;
    var sAccountId = oService.Create(beAccount);

    alert("Account Created. Account ID = " + sAccountId);

    //update an entity
    var beAccountToUpdate = new BusinessEntity("account");
    beAccountToUpdate.attributes["accountid"] = sAccountId;
    beAccountToUpdate.attributes["revenue"] = 1000000000.00;
    oService.Update(beAccountToUpdate);

    alert("Account Updated");

    //retrieve an entity
    var asCols = ["name", "revenue", "createdon", "createdby"];
    var beRetrievedAccount = oService.Retrieve("account", sAccountId, asCols);

    alert("Account Retrieved: " +
    beRetrievedAccount.attributes["name"].value + " : " +
    beRetrievedAccount.attributes["revenue"].value + " : " +
    beRetrievedAccount.attributes["createdon"].value + " : " +
    beRetrievedAccount.attributes["createdby"].value);

    //create an entity with a lookup attribute
    var beContact = new BusinessEntity("contact");
    beContact.attributes["firstname"] = "Joe";
    beContact.attributes["birthdate"] = "2008-01-01T00:00:00";
    beContact.attributes["parentcustomerid"] = new CrmLookup("account", sAccountId);
    var sContactId = oService.Create(beContact);

    alert("Contact Created: " + sContactId);

    //delete an entity
    oService.Delete("account",sAccountId);

    alert("Account Deleted");
}

Fetch Sample

This sample shows how to use the Fetch query language to pull back collections of entities based on the passed in query. For more information on the Fetch query language search for "Using FetchXML" in the CRM 4.0 SDK on MSDN.

function Fetch()
{
    //create the Ascentium_CrmService object
    var oService = new Ascentium_CrmService(orgName.value, serverUrl.value);

    //execute a Fetch query
    var sFetchXml = "<fetch mapping='logical'><entity name='account'><attribute name='accountid'/><attribute name='name'/></entity></fetch>";
    var aoFetchResult = oService.Fetch(sFetchXml);

    //iterate through the aoFetchResult collection
    var sResults = "Accounts:\n";

    for (var i = 0; i < aoFetchResult.length; i++)
    {
        var beResult = aoFetchResult[i];
        sResults += i + ": " + beResult.attributes["accountid"].value + ", " + beResult.attributes["name"].value + "\n";  
    }

    alert(sResults);
}

Asynchronous Sample

This sample shows how to use callbacks to allow the functions to perform asynchronously.

function WhoAmI()
{
    //create the Ascentium_CrmService object
    var oService = new Ascentium_CrmService(orgName.value, serverUrl.value);

    //define a fetchxml query that returns only the current user
    var sFetchXml = "<fetch mapping=\"logical\"><entity name=\"systemuser\"><attribute name=\"fullname\"/><attribute name=\"systemuserid\"/><filter type=\"and\"><condition attribute=\"systemuserid\" operator=\"eq-userid\"/></filter></entity></fetch>";

    //execute the fetch asynchronously by passing a callback function to the Fetch method
    oService.Fetch(sFetchXml, WhoAmICallback);
}

function WhoAmICallback(aoFetchResult)
{
    if (aoFetchResult.length > 0)
    {
        var beUser = aoFetchResult[0];

        alert("You are " + beUser.attributes["fullname"].value + ", System User ID = " + beUser.attributes["systemuserid"].value);
    }
}

Associate/Disassociate Sample

This sample shows how to Associate and Disassociate records. This is used when you have a many-to-many relationship. The fifth parameter is the actual name of the N:N relationship.

function Associate()
{
    //create the Ascentium_CrmService object
    var oService = new Ascentium_CrmService(orgName.value, serverUrl.value);

    //create an account
    var beAccount = new BusinessEntity("account");
    beAccount.attributes["name"] = "Ascentium";
    var sAccountId = oService.Create(beAccount);

    alert("Account Created");

    //create a lead
    var beLead = new BusinessEntity("lead");
    beLead.attributes["fullname"] = "Mr. Lead";
    var sLeadId = oService.Create(beLead);

    alert("Lead Created");

    //associate the account and the lead
    oService.Associate("account", sAccountId, "lead", sLeadId, "accountleads_association");

    alert("Account and Lead Associated");

    //disassociate them
    oService.Disassociate("account", sAccountId, "lead", sLeadId, "accountleads_association");

    alert("Account and Lead Disassociated");

    //delete the account
    oService.Delete("account", sAccountId);

    alert("Account Deleted");

    //delete the lead
    oService.Delete("lead", sLeadId);

    alert("Lead Deleted");
}

SetState Sample

This sample shows how to set the State of a record.

function SetState()
{
    //create the Ascentium_CrmService object
    var oService = new Ascentium_CrmService(orgName.value, serverUrl.value);

    //create an account
    var beAccount = new BusinessEntity("account");
    beAccount.attributes["name"] = "Ascentium";
    var sAccountId = oService.Create(beAccount);

    alert("Account Created");

    //deactivate the account
    oService.SetState("account", sAccountId, "Inactive", -1);

    alert("Account State set to Inactive");

    //delete the account
    oService.Delete("account", sAccountId);

    alert("Account Deleted");
}

 

http://www.ascentium.com/blog/crm/Post129.aspx

 

 

AscentiumCrmService.zip (7,43 kb)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Microsoft CRM 4.0

Related posts

Comments

11/21/2009 3:14:39 PM

java mobile development

I have not known that the CrmService.js script supports sending messages directly to the CRM 4.0 web service utilizing only JavaScript. It was really a news for me. Well it is really great that you showed some samples how to Create, Retrieve, Update and Delete records within CRM. Thanks a lot for the useful and interesting information man!

java mobile development us

2/19/2010 4:40:16 AM

auto insurance

I have not known that the CrmService.js script supports sending messages directly to the CRM 4.0 web service utilizing only JavaScript. It was really a news for me. Well it is really great that you showed some samples how to Create, Retrieve, Update and Delete records within CRM. Thanks a lot for the useful and interesting information man!

auto insurance us

2/20/2010 3:48:59 PM

best registry cleaner

nice post,thanks your sharing!

best registry cleaner us

2/20/2010 7:21:17 PM

registry cleaner review

thanks for sharing

registry cleaner review us

2/24/2010 11:14:24 PM

designer handbags

Gucci bags are one of the most popular designer handbags in the bags fashion world. How to find the disocunt gucci bags, and where to purchase the discount gucci designer handbags? This is a big question for many women in the discount coupon world. Gucci clutches are actually part of the wardrobe of every man and woman wise in this new generation of the fashion bags center. This point will be fully useful for those gucci fans seeking the best discount deals on these online bags stores. Most of these types of women not only to eliminate this important accessory to match their growth of buying fees. Many of these women loving gucci handbags certainly have a sense of pride and mark the bags of the possibility for several reasons to purchase designer handbags in bagsvendor.com. Looking for discount coupon on bagsvendor.com gucci bags buying and not a big problem for anyone to cope in this modern society. There are several ways in which women can intelligently without a doubt the best deal in this discount deisnger bags online store are so attractive for them to show your favorite wardrobe. But the designer handbags on sale stores are offering many cheap bags, you can go to bagsvendor.com to find them more.

designer handbags US

2/25/2010 5:10:36 AM

mountain bike shop

You are a very smart person!

mountain bike shop us

2/26/2010 7:55:14 PM

colic calm

great post. thank you for sharing

colic calm us

2/28/2010 12:11:01 AM

discount designer bags

What a great info, thank you for sharing. this will help me so much in my learning.

discount designer bags US

3/2/2010 12:54:02 PM

designer bag

What a great info, thank you for sharing. this will help me so much in my learning.

designer bag US

3/5/2010 12:55:23 AM

designer bags

I admire the valuable information you offer in your articles. I will bookmark your blog and have my children check up here often. I am quite sure they will learn lots of new stuff here than anybody else!

designer bags US

3/7/2010 11:34:47 PM

discount designer bags

I really appreciate this wonderful post that you have provided for us. I assure this would be beneficial for most of the people.

discount designer bags US

3/8/2010 5:07:54 PM

quick payday loans

I admire what you have done here. I like the part where you say you are doing this to give back but I would assume by all the comments that this is working for you as well. Big thanks for the useful info i found on Ascentium CrmService JavaScript Library.

quick payday loans

3/9/2010 6:24:02 AM

discount bags sale

You did the a great work writing and revealing the hidden beneficial features of BlogEngine.Net, that I found it was popularly used by bloggers nowadays. I think BE has emerged to be one of the best blogging platform right now. I wish you good luck with your blogging experiences.

discount bags sale US

3/9/2010 10:05:07 PM

discount handbag

You did the a great work writing and revealing the hidden beneficial features of BlogEngine.Net, that I found it was popularly used by bloggers nowadays. I think BE has emerged to be one of the best blogging platform right now. I wish you good luck with your blogging experiences.

discount handbag US

3/10/2010 7:11:41 PM

payday loans

Resources like the one you mentioned here will be very useful to me! I will post a link to this page on my blog. I am sure my visitors will find that very useful. Big thanks for the useful info i found on Ascentium CrmService JavaScript Library.

payday loans

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

3/10/2010 9:26:24 PM

Blogging by Ercan TUZUN

Yazar Hakkında

Ercan TÜZÜN Ercan TÜZÜN
Computer Engineer
Software Developer.

E-mail me Send mail

Takvim

<<  March 2010  >>
MoTuWeThFrSaSu
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar

Pages

Recent comments

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010

Sign in