通过Web API调用Action时各种类型输入参数传递值的方法
本人微信公众号:微软动态CRM专家罗勇 ,回复280或者20180906可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me!我的网站是 www.luoyong.me 。
Dynamics 365的Web API功能很强大也越来越强大,流程的一种操作(Action)的功能也很强大也越来越强大(有个特征很好用,就是这些步骤默认组成一个事物,要么都成功,要么都失败)。
工作流中可以调用操作,通过Web API也可以方便的调用。
最近操作的参数增加了Entity这种类型,调用的时候如何赋值呢?我下面这个操作有两个复杂点的输入参数,一个类型为EntityReference的输入参数,一个类型为Entity的输入参数,还有一个类型为EntityReference的输出参数。

为啥要用到Entity类型的参数?典型场景就是我的步骤中需要用到这个Entity记录的非主键,非主属性字段的值,操作中某些字段赋值要用同类型,所以这时候就用上了。
为啥要用EntityReference类型的参数?给某个查找类型的字段赋值就要用到这种参数。
输出参数为EntityReference啥时候用到?你要获取到某个记录的ID时候,比如操作中创建的记录的ID。
官方有篇文章 Use Web API actions 介绍了Entity类型参数的赋值,可以参考,我这里汇总下调用方法如下:
var clientURL = Xrm.Page.context.getClientUrl();
var req = new XMLHttpRequest()
req.open("POST", encodeURI(clientURL + "/api/data/v8.2/new_lytests(93EDAC5A-ACA6-E811-8ACE-005056948ABE)/Microsoft.Dynamics.CRM.new_TestbyLuoYong"), true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.onreadystatechange = function () {
if (this.readyState == 4 /* complete */) {
req.onreadystatechange = null;
if (this.status == 200) {
//注意EntityReference类型输出参数的值是记录的主键值
Xrm.Utility.alertDialog(JSON.parse(this.response).new_workorderid);
}
else {
var error = JSON.parse(this.response).error;
Xrm.Utility.alertDialog("Error." + error.message);
}
}
};
var requestmsg = {};
//Entity类型的参数建议指定@data.type (可以不指定,若是lookup到具体实体,不是customer,partylist类型),格式为Microsoft.Dynamics.CRM.实体逻辑名称
//需要指定记录主键值,还有需要用到的该记录的其他字段值
requestmsg.WorkOrderType = {};
requestmsg.WorkOrderType.new_subjectid='1377FF4A-B494-E811-8ACD-005056948ABE';
requestmsg.WorkOrderType["@data.type"]="Microsoft.Dynamics.CRM.new_subject";
requestmsg.WorkOrderType.new_optionsetfielvalue = 1;
//EntityReference类型的参数指定记录ID就可以
requestmsg.ASP={};
requestmsg.ASP.accountid='FC96BE10-63AF-E811-8ACE-005056948ABE';
req.send(JSON.stringify(requestmsg));
对于参数类型为EntityCollection 类型参数的赋值,可以参考文章 Execute Action with “EntityCollection” Parameter using Web API in Dynamics 365 ,其实就是一个Entity类型参数的数组嘛。
我这里也摘录下官方的原文供各位参考:
When an action requires an entity as a parameter and the type of entity is ambiguous, you must use the @odata.type property to specify the type of entity. The value of this property is the fully qualified name of the entity, which follows this pattern: Microsoft.Dynamics.CRM.+<entity logical name>.
As shown in the Bound actions section above, the Target parameter to the AddToQueue Action is an activity. But since all activities inherit from the activitypointer EntityType, you must include the following property in the entity JSON to specify the type of entity is a letter: "@odata.type": "Microsoft.Dynamics.CRM.letter".
Two other examples are AddMembersTeam Action and RemoveMembersTeam Action because the Members parameter is a collection of systemuser EntityType which inherits it's ownerid primary key from the principal EntityType. If you pass the following JSON to represent a single systemuser in the collection, it is clear that the entity is a systemuser and not a team EntityType, which also inherits from the principal entitytype.
{ "Members": [{
"@odata.type": "Microsoft.Dynamics.CRM.systemuser",
"ownerid": "5dbf5efc-4507-e611-80de-5065f38a7b01"
}]
}
If you do not specify the type of entity in this situation, you can get the following error: "EdmEntityObject passed should have the key property value set.".
通过Web API调用Action时各种类型输入参数传递值的方法的更多相关文章
- 如何让ASP.NET Web API的Action方法在希望的Culture下执行
在今天编辑推荐的<Hello Web API系列教程--Web API与国际化>一文中,作者通过自定义的HttpMessageHandler的方式根据请求的Accep-Language报头 ...
- Only one complex type allowed as argument to a web api controller action.
错误内容: message":"An error has occurred.","exceptionMessage":"Only one c ...
- ABP开发框架前后端开发系列---(10)Web API调用类的简化处理
在较早期的随笔<ABP开发框架前后端开发系列---(5)Web API调用类在Winform项目中的使用>已经介绍了Web API调用类的封装处理,虽然这些调用类我们可以使用代码生成工具快 ...
- ABP开发框架前后端开发系列---(5)Web API调用类在Winform项目中的使用
在前面几篇随笔介绍了我对ABP框架的改造,包括对ABP总体的介绍,以及对各个业务分层的简化,Web API 客户端封装层的设计,使得我们基于ABP框架的整体方案越来越清晰化, 也越来越接近实际的项目开 ...
- ABP开发框架前后端开发系列---(4)Web API调用类的封装和使用
在前面随笔介绍ABP应用框架的项目组织情况,以及项目中领域层各个类代码组织,以及简化了ABP框架的各个层的内容,使得我们项目结构更加清晰.上篇随笔已经介绍了字典模块中应用服务层接口的实现情况,并且通过 ...
- 控制ASP.NET Web API 调用频率与限流
ASP.NET MVC 实现 https://github.com/stefanprodan/MvcThrottle ASP.NET WEBAPI 实现 https://github.com/stef ...
- Web API对application/json内容类型的CORS支持
假设有一简单架构分为前后两部分,其一是Angular构成的前端页面站点,另一个则是通过ASP.NET Web API搭建的后端服务站点.两个站点因为分别布署,所有会有CORS(Cross-Origin ...
- 搭建MVC及WEB API项目框架时碰到的问题集合
前言 刚开始创建MVC与Web API的混合项目时,碰到好多问题,今天拿出来跟大家一起分享下.有朋友私信我问项目的分层及文件夹结构在我的第一篇博客中没说清楚,那么接下来我就准备从这些文件怎么分文件夹说 ...
- ASP.NET Web API 通过参数控制返回类型(JSON|XML)
一个很实用的技巧,可以在访问web api服务的时候指定返回数据的格式类型,比如 json 或者 xml. 因为 web api 默认返回的是XML格式,但是现在json 比较流行,同时网上也有其他的 ...
随机推荐
- MS-UAP发布的UWP的个人隐私策略
我们十分重视您的隐私.本隐私声明解释了我们从您那里收集的个人数据内容以及我们将如何使用这些数据. 我们不收集任何与个人信息相关的数据,只收集与本UWP运行相关的数据,如: 产品使用数据:如每个页面的使 ...
- 快速理解Token,Cookie,Session
在Web应用中,HTTP请求是无状态的.即:用户第一次发起请求,与服务器建立连接并登录成功后,为了避免每次打开一个页面都需要登录一下,就出现了cookie,Session. Cookie Cookie ...
- [Swift]LeetCode1024. 视频拼接 | Video Stitching
You are given a series of video clips from a sporting event that lasted T seconds. These video clip ...
- 调用链Cat介绍
1. 调用链Cat 1.1. 调用链演进 1.2. 开源产品比较 1.3. 监控场景 1.4. cat的增值作用 1.5. cat典型报表 1.5.1. 应用报错大盘 1.5.2. 业务大盘 1.5. ...
- “百度杯”CTF比赛(二月场)-web-writeup
爆破一: 打开网页看到源代码: 根据提示这题就是找变量的值,本想爆破,但不太现实.百度 php获取变量的值 有个超全局数组 $GLOBALS 爆破二: 打开网页看到源代码: 看到了eval() 函数, ...
- 【JVM虚拟机】(4)---性能调优
JVM性能调优 一.调优策略 对于GC的性能主要有2个方面的指标:吞吐量throughput(工作时间不算gc的时间占总的时间比)和暂停pause(gc发生时app对外显示的无法响应). 1.调优的目 ...
- 一个JavaWeb搭建的开源Blog系统,整合SSM框架
搬砖有暇,捣鼓了一个简单的Blog系统(项目地址https://github.com/lenve/JavaEETest/tree/master/MyBlog),适合以下人群学习: 1.已经掌握了jsp ...
- Lucene 06 - 使用Lucene的Query API查询数据
目录 1 Query对象的创建(方式一): 使用子类对象 1.1 常用的Query子类对象 1.2 常用的Query子类对象使用 1.2.1 使用TermQuery 1.2.2 使用NumericRa ...
- leetcode — word-ladder
import java.util.*; /** * Source : https://oj.leetcode.com/problems/word-ladder/ * * * Given two wor ...
- leetcode — valid-palindrome
/** * Source : https://oj.leetcode.com/problems/valid-palindrome/ * * * Given a string, determine if ...