-1

I Wants to get the server Date in Dynamic crm 2011

through new Date() i am getting only the system time.

Hashim
  • 99
  • 1
  • 4
  • 15

1 Answers1

2

Your question really isn't very unclear Hashim. You are trying new Date(); which is JScript. As this is client-side it will not look to the server to retrieve the date and hence you get local system time rather than server time.

You will need code to execute on the server-side to get server time. One solution is a plugin and you would simply use var myDate = DateTime.Now; to get the current system time.

You haven't elaborated on how you wish to use this so I can't tell you what to do with this value now you have it - but perhaps you are using it to populate an entity attribute, e.g. in a pre-update plugin:

if (pluginContext.InputParameters.Contains("Target") && 
    pluginContext.InputParameters["Target"] is Entity)
{
    // Obtain the target entity from the input parmameters.
    var entity = (Entity)pluginContext.InputParameters["Target"];
    // get current date/time
    var now = DateTime.Now;
    entity.Attributes.Add("new_mydatetimefield", now);
}
Pawel Gradecki
  • 3,476
  • 6
  • 22
  • 37
Greg Owens
  • 3,878
  • 1
  • 18
  • 42
  • I want to use this as an General plugin for some entities,and i have one date field which is common in all these entities,if i filled this field with passed date it should show an alert message otherwise it should save. – Hashim Jun 26 '12 at 11:02