第365章:一个人JavaScript retrieveRecord函数从查找字段中检索值和名称

kfgdxczn  于 2023-09-29  发布在  Java
关注(0)|答案(1)|浏览(82)

我使用retrieveRecord函数从查阅中检索查阅值,然后将这些值分配给其他查阅字段。

var result = Xrm.WebApi.retrieveRecord(sellTo[0].entityType, customerId, '?$select=name,_kk_paymentterms_value,_kk_shippingmethod_value,_kk_freightterms_value');
        paymentTerms = result._kk_paymentterms_value;
        shippingMethod = result._kk_shippingmethod_value;
        freightTerms = result._kk_freightterms_value;

我需要名称来设置查阅字段的值,如何检索它们?

yr9zkbsy

yr9zkbsy1#

您可以在请求中添加一个Prefer头值:

GET [Organization URI]/api/data/v9.2/contacts?$top=100
&$select=fullname,_parentcustomerid_value,statuscode,createdon
&$filter=firstname eq 'henk' and lastname eq 'boeijen' and _parentcustomerid_value ne null

Accept: application/json  
OData-MaxVersion: 4.0  
OData-Version: 4.0
Prefer: odata.include-annotations="OData.Community.Display.V1.FormattedValue"

现在,(本地化的)显示值被添加到选项、布尔值、查找值、日期等的响应中。

{
  "@odata.context": "[Organization URI]/api/data/v9.2.23084.206/$metadata#contacts(fullname,_parentcustomerid_value,statuscode,createdon)",
  "value": [
    {
      "@odata.etag": "W/\"831620324\"",
      "fullname": "Boeijen, Henk van",
      "_parentcustomerid_value@OData.Community.Display.V1.FormattedValue": "My Company Name",
      "_parentcustomerid_value": "d96679fb-0e61-ed11-9561-0022487fe2b5",
      "[email protected]": "Active",
      "statuscode": 1,
      "[email protected]": "28-10-2022 11:17",
      "createdon": "2022-10-28T09:17:55Z",
      "contactid": "e8ef9664-a152-ed11-bba1-0022487feed1"
    }
  ]
}

另请参阅使用Web API查询数据:格式化值- MS Learn。

相关问题