繁体   English   中英

使用Dynamics CRM 4.0中的JavaScript计算年龄

[英]Calculate the Age using javascript in Dynamics CRM 4.0

首先,我对Dynamics crm非常陌生。

我有这样的情况,我必须计算发生案件且涉及的人类型为“投诉人”的人的年龄

为此,我们有3个Custome实体

new_Case 
    Occurrence Date
new_involvePerson
    Involved Person Type(following are types)
        - Complainant
        - Supervisor
        - Investigator
and New_person
        - DOB

现在,用户更新了事件的发生日期,我必须计算投诉人的年龄

保存事件案例时,可以在Javascript OnSave中进行吗? 还是我必须创建工作流程或插件? 是否可以获取示例代码

提前致谢

是的,有可能。 您只需要编写一个函数并在事件表单保存时触发它即可。

检查“出现日期”是否为空,然后检索new_involvePerson的类型,如果该类型等于“投诉人”,则很容易就可以检索“ presentPerson”的出生日期并计算年龄。

calculateAge = function (date) {

    var birthDate = new Date(date);
    var todayDate = new Date();
    var todayYear = todayDate.getFullYear();
    var todayMonth = todayDate.getMonth();
    var todayDay = todayDate.getDate();
    var birthYear = birthDate.getFullYear();
    var birthMonth = birthDate.getMonth();
    var birthDay = birthDate.getDate();

    var age = todayYear - birthYear;

    if (todayMonth < birthMonth) {
        age--;
    }

    if (birthMonth == todayMonth && todayDay < birthDay) {
        age--;
    }
    if (age != undefined && age != null) {
        Xrm.Page.getAttribute("yourfieldhere").setValue(age);
    }
    else {
        Xrm.Page.getAttribute("yourfieldhere").setValue(null);
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM