Get LocalTimeFromUtcTime in JavaScript using Xrm.WebApi.online.execute function call.

Very good tip Rajneet. Resharing

Ranjeet Patel

sometime we need to get the local time of use in local timezone set in personal setting of dynamics using client side script.

I needed to make sure that i am passing each and everything correctly in Xrm.WebApi.online.execute as this function throws very generic errors and doesn’t give any clue of real missing parameter or syntax error.

Code sample with some comments :

////Microsoft Documentation can be found on this url “https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-webapi/online/execute”

function LocalTimeFromUtcTimeRequest(timeZoneCode, utcTime) {
this.TimeZoneCode = timeZoneCode;
this.UtcTime = utcTime;
}

LocalTimeFromUtcTimeRequest.prototype.getMetadata = function () { //// Make sure to write the cunstructor in this way so that the metadata goes to proto
return {
boundParameter: null,
parameterTypes: { ////This property needs two parameters TimeZoneCode, UtcTime
“TimeZoneCode”: {
“typeName”: “Edm.Int32”,
“structuralProperty”: 1 ////1 is for PrimitiveType data structures
},
“UtcTime”: {
“typeName”: “Edm.DateTimeOffset”, ////For Dates we need to use DateTimeOffset and not the DateTime
“structuralProperty”: 1 ////1 is…

View original post 118 more words

Published by

Debajit

I am a Dynamics CRM Most Valuable Professional (MVP) with 12 years of experience in Microsoft .NET Technologies and 9 years of dedicated experience in Microsoft Dynamics CRM. I have worked with companies like Microsoft, SanDisk, PwC, TMF Group and have extensive experience of implementing complex CRM solutions from both offshore and client side. Currently the face of XrmForYou.com with significant experience in delivering corporate training on Dynamics CRM and have already delivered multiple projects to client through XrmForYou.com Author of multiple tools on codeplex including the 'Role Based Views' and 'CRM-Sharepoint Metadata manager & Attachment Extractor' which are available for commercial use under XrmForYou.com For consulting/ training, drop me a note at info@xrmforyou.com or visit our website www.xrmforyou.com

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s