cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
LostInDynamics
Regular Visitor

Updating datetime with WebApi offline

I'm using Xrm.WebApi.offline.updateRecord to update a Dynamics record offline in my PCF component (as documented here: https://docs.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/xrm-weba...).

 

Other fields update smoothly offline, but if I add a datetime field to the mix & try to save, I get an uninformative error "An error has occurred...". I have tried several formats for the datetime with no success. What kind of date format is expected here?

 

 

 

let data: any = {};

data["myDateField"] = "dd/MM/yyyy hh:mm AM/PM";

Xrm.WebApi.offline.updateRecord("myentity", recordId, data).then(
	function success(result) {
		console.log("Entry updated.");
	},
	function (error) {
		console.log(error.message);
	}
);

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
cchannon
Super User
Super User

You're trying to insert a string into that col, not a datetime. You have to actually construct the datetime value with new Date():

let myDate = new Date("01/01/2022");

or:

let myDate = new Date(2022,01,01,0,0,0,0);

JavaScript Date Objects (w3schools.com) 

View solution in original post

2 REPLIES 2
cchannon
Super User
Super User

You're trying to insert a string into that col, not a datetime. You have to actually construct the datetime value with new Date():

let myDate = new Date("01/01/2022");

or:

let myDate = new Date(2022,01,01,0,0,0,0);

JavaScript Date Objects (w3schools.com) 

DianaBirkelbach
Super User
Super User

Hi @LostInDynamics , 

 

If was surely not the cause for your issue, but just wanted to add that using the Xrm.* object inside a PCF is not supported, 

The right way would be to use the context.WebAPI, offered by the PCF sdk. That will automatically switch between online and offline if needed: https://docs.microsoft.com/en-us/power-apps/developer/component-framework/reference/webapi?WT.mc_id=...

 

 

Kind regards,
Diana
----------
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Users online (1,751)