【问题标题】:How to Access the Server Date in Dynamic CRM 2011 through Javascript or Plugin?如何通过 Javascript 或插件访问 Dynamic CRM 2011 中的服务器日期?
【发布时间】:2012-06-26 07:10:00
【问题描述】:

我想在 Dynamic crm 2011 中获取服务器日期

通过 new Date() 我只得到系统时间。

【问题讨论】:

    标签: c# javascript dynamics-crm dynamics-crm-2011 dynamics-crm-4


    【解决方案1】:

    你的问题真的不是很清楚哈希姆。您正在尝试 new Date(); 这是 JScript。由于这是客户端,它不会通过服务器来检索日期,因此您获得的是本地系统时间而不是服务器时间。

    您需要在服务器端执行代码以获取服务器时间。一种解决方案是插件,您只需使用var myDate = DateTime.Now; 即可获取当前系统时间。

    您还没有详细说明您希望如何使用它,所以现在我无法告诉您如何处理该值 - 但也许您正在使用它来填充实体属性,例如在预更新插件中:

    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);
    }
    

    【讨论】:

    • 我想将其用作某些实体的通用插件,并且我有一个在所有这些实体中通用的日期字段,如果我用传递的日期填写此字段,它应该显示一条警报消息,否则它应该保存。
    猜你喜欢
    • 1970-01-01
    • 2014-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-18
    • 2014-02-11
    • 2016-09-27
    • 1970-01-01
    相关资源
    最近更新 更多