在 Dynamics CRM 4.0 中使用 javascript 计算年龄

发布于 12-21 07:59 字数 438 浏览 7 评论 0原文

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

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

因为我们有3个客户实体

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

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

当事件案例保存时,是否可以在Javascript OnSave中执行此操作? 或者我必须创建工作流程或插件吗?是否可以获得示例代码

提前致谢

First of all, I am very new in dynamics crm.

I have situation where I have to calculate the age of person where case occurred
and involved person type is "Complainant"

For that we have 3 Custome Entity

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

Now, user update the Occurrence Date in Incident, I have to calculate age of complainant Involved Person

Is it possible to do in Javascript OnSave when Incident Case save?
Or do i have to create a workflow or Plug-in? Is it possible to get the sample code

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自由范儿2024-12-28 07:59:36

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

检查 Occurence Date 是否不为空,然后检索 new_involvePerson 的类型,如果等于 Complainant,那么您只需检索volvePerson 的出生日期并计算年龄就很容易了。

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

Yes it's possible. You just have to write a function and trigger it on the on save of the incident form.

Check if Occurence Date is not empty then Retrieve the new_involvePerson's type and if that equals Complainant and then it's easy you just Retrieve the involvePerson's date of birth and calculate the age.

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);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文