Dynamics365 JS

本文介绍了如何在Dynamics365中使用JavaScript,包括在Web资源和表单上注册JS,处理状态码,给lookup字段赋值,清空字段,锁定表单字段,使用executeContext参数,调用Web API查询数据,以及按钮事件和显示控制。示例代码涵盖各种操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • JS先要在web resouce中注册 再在表单上注册事件。

  • merge 时,通过来 下面的代码 获得的第二个记录的上的值。

    Entity subordinateId = (Entity)context.InputParameters["SubordinateId"];
    Entity duplicateEntity = service.Retrieve("account", subordinateId.Id, new ColumnSet(true));
    
  • statecode 0 可用 1不可用。

  • 两个选项的结果值 为true or false。

  • JS中给 lookup字段赋值是 使用下列的代码作为参考。

    var array = [];
    array[0] = {};
    array[0].id = ents[0]["accountid"];
    array[0].name = ents[0]["accountid@OData.Community.Display.V1.FormattedValue"];
    array[0].entityType = "account";
    formcontext.getAttribute("new_accountid").setValue(array);
    
  • 当要对js某个字段进行清空时,使用如下示例代码

    formcontext.getAttribute("new_accountid").setValue(null);//lookup 字段
    formcontext.getAttribute("new_beforezpoint").setValue(null);//decimal 字段
    
  • 锁定表单上所有字段 示例代码

    var cs = formcontext.ui.controls.get();//获取所有字段
    for (var i in cs) {//对字段进行遍历
     	var c = cs[i];
        if (c.getName() != "" && c.getName() != null) {
        	if (!c.getDisabled()) { 
              c.setDisabled(true); //禁用
            }
        }
    }
    
  • 当JS的function中使用execontext参数时,代码示例

    function lockAllField(execontext) {
    	debugger;
    	var formcontext = execontext.getFormContext();
    }
    
  • 注册在表单上时记得✔选在这里插入图片描述

  • JS中调用Web API查询数据示例代码

    Xrm.WebApi.retrieveMultipleRecords("account", "?$select=accountid,new_customerid,new_usablepoint&$filter=new_customerid eq '" + bpid + "'and new_pim eq false and statecode eq 0").then(function (success) {
    	var ents = success.entities;
      	//TODO
    }, function (error) {
      	//TODO
    });
    
  • 按钮触发 改变字段的值 保存并退出 示例代码

    function commitRibbonClick2() {
        debugger;
        Xrm.Page.getAttribute("new_status").setValue(1);//设置值and todo
        Xrm.Page.data.entity.save("saveandclose");//保存并关闭页面
    }
    
  • 按钮的显隐控制 工具配置方法链接

    function setVisible() {
        debugger;
        var status = Xrm.Page.getAttribute("new_status").getValue();
        return status==0;//true 为显示 false 为隐藏
    } 
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值