• Power Apps使用oData访问表数据并赋值前端


     

    在使用OData查询语法通过Xrm.WebApi.retrieveMultipleRecords方法过滤数据时,你可以指定一个OData $filter 参数来限制返回的记录集。

    以下是一个使用Xrm.WebApi.retrieveMultipleRecords方法成功的例子,它使用了OData $filter 参数来查询实体的记录:

    1. // 使用 OData 查询语法查询数据
    2. // 定义要查询的实体类型
    3. var entityName = "crd18_associate";//"crd18_d28a3c8a2f9d4fccb054dc12c63a4b2c";
    4. // 定义OData查询参数
    5. var query = "?$select=crd18_department,crd18_company,crd18_requestor,crd18_location,crd18_eligible,crd18_quantity&$filter=crd18_cname eq '"+currentUserName+"'";
    6. // 使用Xrm.WebApi.retrieveMultipleRecords方法进行查询
    7. Xrm.WebApi.retrieveMultipleRecords(entityName, query).then(
    8. function success(results) {
    9. // 成功时的回调函数
    10. if (results.entities.length > 0) {
    11. for (var i = 0; i < results.entities.length; i++) {
    12. console.log(results.entities[i].crd18_department);
    13. formContext.getAttribute("crd18_department").setValue(results.entities[i].crd18_department);
    14. formContext.getAttribute("crd18_company").setValue(results.entities[i].crd18_company);
    15. formContext.getAttribute("crd18_requestor").setValue(results.entities[i].crd18_requestor);
    16. formContext.getAttribute("crd18_location").setValue(results.entities[i].crd18_location);
    17. formContext.getAttribute("crd18_eligible").setValue(results.entities[i].crd18_eligible);
    18. formContext.getAttribute("crd18_entitled_qty").setValue(results.entities[i].crd18_quantity);
    19. }
    20. }
    21. else {
    22. console.log("No records found");
    23. formContext.getAttribute("crd18_requestor").setValue("No records found");
    24. }
    25. },
    26. function (error) {
    27. // 错误处理
    28. console.log(error.message);
    29. }
    30. );

    console.log需要F12打开浏览器开发者工具查看

  • 相关阅读:
    关于hive的时间戳
    Apache反向代理&负载均衡
    spring笔记一(bean/IoC)
    Java 反射机制详解
    Simple WPF: WPF 透明窗体和鼠标事件穿透
    Java 初学者必备核心基础知识有哪些?
    java毕业生设计在线药物配送系统计算机源码+系统+mysql+调试部署+lw
    RH8任务计划(单一/循环)
    Clang-format格式化及配置参数
    【ML06】Learning Rate 学习率
  • 原文地址:https://blog.csdn.net/weixin_41850878/article/details/140412498