在Dynamics 365和JavaScript中显示相关实体

问题描述 投票:0回答:1

我用3个字段创建了实体:

  • 文本域
  • 数字字段
  • 与账户的关系

我创建了JS代码来显示或编辑这些字段,但是有没有办法使用来自我的实际实体的formContext来显示来自Account实体的数据?

function test(executionContext) {
    var formContext = executionContext.getFormContext();    

    //text
    var text = formContext.data.entity.attributes.getByName('new_text').getValue();
    text.setValue("new text");

    //number
    var number = formContext.data.entity.attributes.getByName('new_number').getValue();
    number.setValue(5);

    //id field for another entity
    var number = formContext.data.entity.attributes.getByName('new_accountid').getValue();

    //my ideal solution would've look like this, but it doesn't working
    number.getParent().attributes.getByName('account_name').getValue();

}
javascript dynamics-crm microsoft-dynamics dynamics-365 dynamics-crm-365
1个回答
3
投票

与Account的关系是一个查找字段。 How to get/set the lookup attribute value?

你可以通过以下方式获得它的价值:

var lookup = new Array();
lookup = formContext.getAttribute("Lookup Field Name").getValue();
if (lookup != null) {
    var name = lookup[0].name;
    var id = lookup[0].id;
    var entityType = lookup[0].entityType;
}

您可以通过以下方式设置其值:

formContext.getAttribute("Lookup Field Name").setValue([{ id: recordid, name: recordname, entityType: entityname}]);

如果您只想以当前实体形式显示该查找记录中的某些其他属性,则可以在当前实体中使用该查找实体的快速视图形式。

如果要从“帐户查找记录”中检索其他属性并将其设置为当前实体表单字段,请使用Xrm.Webapi获取它并设置该值。

© www.soinside.com 2019 - 2024. All rights reserved.