You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在TypeScript中用formContext替代已弃用的Xrm.Page?

替换Xrm.Page为formContext的正确修改方式

直接将代码里的Xrm.Page替换为函数参数传入的context即可,修改后的代码如下:

export function OpenQuickCreateForm(formId: string = '9add862d-3ceb-4342-99cf-fe5a952eebf8', context: Xrm.FormContext): void {
    const emailadd = context.getAttribute("emailaddress1");
    const firstName = context.getAttribute("firstname");
    const lastName = context.getAttribute("lastname");

    // 后续如果需要获取属性值,记得调用getValue(),示例:
    // const emailValue = emailadd?.getValue();
}

额外注意两点:

  • 确保在Dynamics 365表单的事件配置中,勾选了传递执行上下文选项,这样函数才能拿到有效的formContext实例
  • 如果要读取属性的实际值,不要忘了调用getValue()方法,建议加上可选链?.避免属性不存在时抛出错误

内容的提问来源于stack exchange,提问作者Drey DG

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 09:14:50