Wednesday, October 17, 2012
Wednesday, June 27, 2012
Dealing with Dates in ODATA Endpoints.
I quote from MSDN:
When you retrieve records using the REST endpoint date values are returned as strings that use the format “\/Date()\/” where is the number of milliseconds since midnight January 1, 1970. For example: "\/Date(1311170400000)\/". All values returned from Microsoft Dynamics CRM represent the Universal Coordinated time (UTC) values.
Sample Code:
Note: In the below code sample "result" is the response from the ODATA querry.
Once the string date values are converted to Date objects you can use a variety of JScript methods to display the date as a string that can be displayed in a user interface .
Have fun working with ODATA!!
When you retrieve records using the REST endpoint date values are returned as strings that use the format “\/Date(
Sample Code:
Note: In the below code sample "result" is the response from the ODATA querry.
//Retrieving the Date object as string
var stringDateValue = eval(result.CreatedOn).toString();
Once the string date values are converted to Date objects you can use a variety of JScript methods to display the date as a string that can be displayed in a user interface .
var createdOn = new Date(parseInt(stringDateValue.replace("/Date(", "").replace(")/", ""), 10));
createdOn = getODataLocalDateFilter(createdOn);
function getODataLocalDateFilter(date) {
//-- Description: For converting the date object to local time format
//-- You can also convert this to UTC Date format
//-- UTC Usage: getUTCMonth(), getUTCFullYear(), getUTCHours() ...
var monthString;
var rawMonth = (date.getMonth()+1).toString();
if (rawMonth.length == 1) {
monthString = "0" + rawMonth;
}
else
{ monthString = rawMonth; }
var dateString;
var rawDate = date.getUTCDate().toString();
if (rawDate.length == 1) {
dateString = "0" + rawDate;
}
else
{ dateString = rawDate; }
var DateFilter = "";
DateFilter += date.getFullYear() + "-";
DateFilter += monthString + "-";
DateFilter += dateString;
DateFilter += " T" + date.getHours() + ":";
DateFilter += date.getMinutes() + ":";
DateFilter += date.getSeconds() + ":";
DateFilter += date.getMilliseconds();
return DateFilter;
}
Have fun working with ODATA!!
Tuesday, June 26, 2012
Updating the Owner in CRM.
Updating the Owner Id in CRM 4.0:
Note: Plase, make sure to update the "ownerUpdatingEntity" with one you are trying to update. Also, Replace the "Entity_Name" with the name of the entity you are updating.
private static void AssignUser(CrmService service, Guid ownerId, Guid recordId)
{
SecurityPrincipal assignee = new SecurityPrincipal();
assignee.PrincipalId = ownerId;
TargetOwnedDynamic ownerUpdatingEntity = new TargetOwnedDynamic();
ownerUpdatingEntity.EntityId = recordId;
ownerUpdatingEntity.EntityName = "Entity_Name";
AssignRequest assign = new AssignRequest();
assign.Assignee = assignee;
assign.Target = ownerUpdatingEntity;
AssignResponse assignResponse = (AssignResponse)service.Execute(assign);
}
Updating the Owner Id in CRM 2011:
Note: Please, make sure to replace the "Account.EntityLogicalName" with the right Entity in the below code.
private static void AssignUser(IOrganizationService service, Guid ownerId, Guid recordId)
{
// Create the Request Object and Set the Request Object's Properties
AssignRequest assign = new AssignRequest
{
Assignee = new EntityReference(SystemUser.EntityLogicalName, ownerId),
Target = new EntityReference(Account.EntityLogicalName,recordId)
};
// Execute the Request
service.Execute(assign);
}
Hope this helps!
Tuesday, June 5, 2012
Retrieve Plugin: MS CRM 2011
I was curious in retrieving the
information from the context in Retrieve Plugin message. I
realized that the context.InputParameters[“Target”], would return null/
throw exception in the retrieve plugin message.
Monday, January 30, 2012
Dealing with N:N Relationship in MS CRM - 2011
In the latest version of MS CRM 2011, the AssociateEntitiesRequest class has been deprecated. Now, we need to make use of AssociateRequest Class.
Here is an example to associate an entity record.
Here is an example to associate an entity record.
// Create the request object and set the monikers with the // orderproduct_association relationship. AssociateRequest productOrder = new AssociateRequest { Target = new EntityReference(order.EntityLogicalName, orderId), RelatedEntities = new EntityReferenceCollection { new EntityReference(product.EntityLogicalName, productId) }, Relationship = new Relationship("orderproduct_association") }; // Execute the request. _serviceProxy.Execute(productOrder);
Subscribe to:
Posts (Atom)