【问题标题】:How to setvalue on onload event in Dynamics crm如何在 Dynamics crm 中设置 onload 事件的值
【发布时间】:2023-03-08 08:03:01
【问题描述】:

我正在使用 fetch 到客户端获取记录,我需要将 fetch 中的数据填充到我创建的新记录中的字段中(在客户端填充字段),但是当我使用设置值时,我得到一个错误:

无法读取 null 的属性“setValue”

我不明白为什么,字段是Null,因为新记录是空的,为什么我不能填?

function OnLoad() {
  formType = Xrm.Page.ui.getFormType();
  if(formType == formTypes.Create){
    copyCatNewRecord();
  }
}

function copyCatNewRecord(){
  var xml;
  xml ="<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' count='1'>"
  xml += "<entity name='needs'>"
  xml += "<attribute name='needsid' />"
  xml += "<attribute name='needsname' />"   
  xml += "<order attribute='modifiedon' descending='true' />"
  xml +=  "</entity></fetch>"

  var ret = frameworkGlobal.ExecuteFetchRequest(xml);
  var currValue = ret[0].needsid.Value;

  // This line returns an error  
  Xrm.Page.getAttribute("needs").setValue(currValue);
}

【问题讨论】:

    标签: fetch dynamics-crm-2016 xrm


    【解决方案1】:

    无法读取 null 的属性“setValue”

    当在不存在的字段上调用 ​​Xrm.Page.getAttribute() 时,通常会收到此错误消息。那么,您确定 "needs" 是表单上实际字段的模式名称吗?该字段可能应该有一个前缀,例如new_,即"new_needs"

    【讨论】:

      【解决方案2】:

      您收到的错误表明未找到您尝试写入数据的字段。确保该字段出现在表单上,​​并且您在尝试访问它时使用了逻辑名称(请参阅 Dave Clark 的回答)。

      如果您尝试从表单上存在的 Html 网络资源中设置值,请使用 window.parent 访问该字段 > window.parent.Xrm.Page.getAttribute("prefix_fieldname").setValue(currValue);

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-03-03
        • 2016-08-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多