XrmServiceToolkit Samples (Non working code snippets)
function ChangeStatusReason_toReject() {
XrmServiceToolkit.Soap.SetState("entityname", Xrm.Page.data.entity.getId(), statecode, statuscode,false);
Xrm.Page.data.refresh(true).then(null, null);//for refreshing form
}
// Retrieve
function Retrieve() {
var salesOrder = XrmServiceToolkit.Soap.Retrieve("salesorder", salesorderid,
["name", "ad_solution", "customerid", "ad_contactid", "ad_licencenumber", "ad_costholderid"]);
if (salesOrder.attributes["name"] != null)
{
salesOrderName = salesOrder.attributes["name"].value;
}
if (salesOrder.attributes["ad_solution"] != null)
{
salesOrderad_solution = salesOrder.attributes["ad_solution"].value;
}
if (salesOrder.attributes["customerid"] != null)
{
salesCustomerId = salesOrder.attributes["customerid"].id;
}
if (salesOrder.attributes["ad_contactid"] != null)
{
salesad_ContactId = salesOrder.attributes["ad_contactid"].id;
}
if (salesOrder.attributes["ad_licencenumber"] != null)
{
salesad_licencenumber = salesOrder.attributes["ad_licencenumber"].value;
}
if (resourceid) {
salesad_costholderid = resourceid;
}
else if (salesOrder.attributes["ad_costholderid"] != null)
{
salesad_costholderid = salesOrder.attributes["ad_costholderid"].id;
}
}
}
// Create Sample
function Create() {
var incident = new XrmServiceToolkit.Soap.BusinessEntity("incident");
incident.attributes["ad_orderid"] = { id: salesorderid, logicalName: "salesorder", type: "EntityReference" };;
incident.attributes["title"] = salesOrderName;
incident.attributes["caseorigincode"] = { value: 200000, type: "OptionSetValue"}; // Sales Order
incident.attributes["casetypecode"] = { value: 200006, type: "OptionSetValue" }; // Implementation
incident.attributes["ad_dnrma"] = "";
var caseId = XrmServiceToolkit.Soap.Create(incident);
}
// Create Note
function AddNote(entityId, entityName, noteSubject, noteText) {
var note = new XrmServiceToolkit.Soap.BusinessEntity("annotation");
note.attributes["subject"] = noteSubject;
note.attributes["notetext"] = noteText;
note.attributes["objectid"] = { id: entityId, logicalName: entityName, type: "EntityReference" };
return XrmServiceToolkit.Soap.Create(note);
}
// RetrieveMultiple Sample
function GetServiceTypeDuration(serviceTypeId)
{
if (serviceTypeId == null) return 0;
var query = "<a:ColumnSet>" +
"<a:AllColumns>false</a:AllColumns>" +
"<a:Columns xmlns:b='http://schemas.microsoft.com/2003/10/Serialization/Arrays'>" +
"<b:string>ad_defaultduration</b:string>" +
"<b:string>ad_defaultserviceid</b:string>" +
"</a:Columns>" +
"</a:ColumnSet>" +
"<a:Criteria>" +
"<a:Conditions />" +
"<a:FilterOperator>And</a:FilterOperator>" +
"<a:Filters>" +
"<a:FilterExpression>" +
"<a:Conditions>" +
"<a:ConditionExpression>" +
"<a:AttributeName>ad_servicetypeid</a:AttributeName>" +
"<a:Operator>Equal</a:Operator>" +
"<a:Values xmlns:b='http://schemas.microsoft.com/2003/10/Serialization/Arrays'>" +
"<b:anyType i:type='c:string' xmlns:c='http://www.w3.org/2001/XMLSchema'>" + serviceTypeId + "</b:anyType>" +
"</a:Values>" +
"</a:ConditionExpression>" +
"</a:Conditions>" +
"<a:FilterOperator>And</a:FilterOperator>" +
"<a:Filters />" +
"</a:FilterExpression>" +
"</a:Filters>" +
"</a:Criteria>" +
"<a:Distinct>false</a:Distinct>" +
"<a:EntityName>ad_servicetype</a:EntityName>" +
"<a:LinkEntities />" +
"<a:Orders />" +
"<a:PageInfo>" +
"<a:Count>0</a:Count>" +
"<a:PageNumber>0</a:PageNumber>" +
"<a:PagingCookie i:nil='true' />" +
"<a:ReturnTotalRecordCount>false</a:ReturnTotalRecordCount>" +
"</a:PageInfo>" +
"<a:NoLock>false</a:NoLock>";
var retrieved = XrmServiceToolkit.Soap.RetrieveMultiple(query);
if (retrieved.length != null) {
if (retrieved.length !=0) {
var defaultDuration = null;
var defaultService = null;
var defaultServiceName = null;
if (retrieved[0].attributes["ad_defaultserviceid"] != null)
{
defaultService = retrieved[0].attributes["ad_defaultserviceid"].id;
defaultServiceName = retrieved[0].attributes["ad_defaultserviceid"].name;
}
else
{
defaultService = '8A4EB7CC-3925-DF11-A6AA-00215AF2A210';
defaultServiceName = "Default";
}
if (retrieved[0].attributes["ad_defaultduration"] != null)
{
defaultDuration = retrieved[0].attributes["ad_defaultduration"].value;
}
return {defaultDuration:defaultDuration, defaultService:defaultService, defaultServiceName:defaultServiceName};
}
}
return null;
}