Get DateTime formate from Retrieved stringDateAttribute Using Odata Java Script – MS CRM 2011

Get DateTime formate from Retrieved stringDateAttribute  Using Odata Java Script:

Some times you may get date time value as milli seconds in the below format as “/Date(1371723451000)/”

var RetrievedDate = “/Date(1371723451000)/”;

to convert this into normal date you need to pass “RetrievedDate” string to the below highlited area.

var DateValue = new Date(parseInt(RetrievedDate.replace(“/Date(“, “”).replace(“)/”, “”), 10));

Now you will get DateValue in UTC date time format.

Cheers,

Trigger WorkFlow Using JavaScript – MS CRM 2011

Trigger WorkFlow Using JavaScript

var workflowGuid = “<Work Flow GUid>”;
var entityId = “<Record Guid>”;

function TriggerWorkflow(entityId,workflowGuid) {

/*Generate Soap Body.*/

var soapBody = “<soap:Body>” +
” <Execute xmlns=’http://schemas.microsoft.com/crm/2007/WebServices’>&#8221; +
” <Request xsi:type=\’ExecuteWorkflowRequest\’>” +
” <EntityId>” + entityId + “</EntityId>” +
” <WorkflowId>” + workflowGuid + “</WorkflowId>” +
” </Request>” +
” </Execute>” +
“</soap:Body>”;

/*Wrap the Soap Body in a soap:Envelope.*/
var soapXml = “<soap:Envelope ” +
” xmlns:soap=’http://schemas.xmlsoap.org/soap/envelope/&#8217; ” +
” xmlns:xsi=’http://www.w3.org/2001/XMLSchema-instance&#8217; ” +
” xmlns:xsd=’http://www.w3.org/2001/XMLSchema’>&#8221; +
GenerateAuthenticationHeader() +
soapBody +
“</soap:Envelope>”;

/* Create the XMLHTTP object for the execute method.*/
var xmlhttp = new ActiveXObject(“Msxml2.XMLHTTP”);
xmlhttp.open(“POST”, “/MSCRMservices/2007/crmservice.asmx”, false);
xmlhttp.setRequestHeader(“Content-Type”, “text/xml; charset=utf-8”);
xmlhttp.setRequestHeader(“SOAPAction”, “http://schemas.microsoft.com/crm/2007/WebServices/Execute&#8221;);

/* Send the XMLHTTP object. */
xmlhttp.send(soapXml);
alert(“The workflow has been triggered successfully”);

}

 

Cheers,

QueryExpression Generic Function to Get GUID of a Specific Record – MS CRM 2011 C# Code

QueryExpression Generic Function to Get GUID of a Specific Record

 

private Guid GetRecordGuid(string EntityName , ColumnSet Colset, string AttributeName , string ConditionAttributeEquallTo ,string guidAttributeLogicalName)
{
Guid RecordId = Guid.Empty;
try
{
QueryExpression qe = new QueryExpression();
qe.EntityName = EntityName;
qe.ColumnSet = Colset;
ConditionExpression cond = new ConditionExpression(AttributeName, ConditionOperator.Equal, ConditionAttributeEquallTo);
FilterExpression fl = new FilterExpression();
fl.Conditions.Add(cond);
qe.Criteria.AddFilter(fl);
EntityCollection SearchContactResult = service.RetrieveMultiple(qe);
if (SearchContactResult.Entities.Count == 1)
{
foreach (Entity result in SearchContactResult.Entities)
{
RecordId = result.GetAttributeValue<Guid>(guidAttributeLogicalName);
}
}
}
catch (Exception ex)
{
lblContactSetResults.Text = ex.ToString();
}

return RecordId;
}

Cheers,