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)