Reputation: 18092
I try to set a Date field on my form from inside a Silverlight Web Resource but the form field remains empty:
var xrm = (ScriptObject)HtmlPage.Window.GetProperty("Xrm");
var page = (ScriptObject)xrm.GetProperty("Page");
var startdate = (ScriptObject)page.Invoke("getAttribute", "scheduledstart");
startdate.Invoke("setValue", DateTime.Now.ToUniversalTime().ToString("MM/dd/yyyy"));
While the above code works fine for other field types (string, int, OptionSet, etc.) there seems to be an error in the way I try to set the date value.
Side note: I don't use dynamic
because it seems not to work when deployed in an MS CRM online environment (but works on-premise).
Upvotes: 1
Views: 319
Reputation: 241920
You're formatting the date to a string, so it's trying to pass a string into a Javascript Date field. Just pass it as a DateTime. The ScriptObject class is designed to convert properly from .Net to Javascript. reference here
startdate.Invoke("setValue", DateTime.Now);
Upvotes: 1