在Dynamics 365中使用SURVEYJS代替对话(Dialog)制作话术
本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复269或者20180318可方便获取本文,同时可以在第一间得到我发布的最新的博文信息,follow me!我的网站是 www.luoyong.me 。
微软官方有个文档:Important changes coming in Dynamics 365 Customer Engagement ,文档中明确提到,已经不推荐使用对话(Dialogs are deprecated),当然,它原生不支持多语言,这也是一个缺点(可以动脑经通过获取当前用户语言打开不同的Dialog来模拟支持多语言),原文如下:
Dialogs are deprecated
You can use a Dialog process to create an interactive step-by-step data entry form that requires user input to start and run to completion. When you start the dialog process, a wizard-like interface is presented; users make selections or enter data as they progress through each page of the wizard.
Dialogs are deprecated and are replaced by mobile task flows (available as of the December 2016 update), and business process flows. Both task flows and business process flows will continue to evolve to make the transition easier.
那我们如果要制作像对话一样的东西,可有类似的Js框架可以使用?搜索了一下找到了一个,叫做 SURVEYJS,官方网址是 https://surveyjs.io ,开源的(看起来是使用TypeScript写的),MIT协议,该协议是可以商用的,需要保留版权和许可信息,下面这张图表明了MIT协议的特征:

闲话少说,我们来讲讲如何用,我这里使用JQuery版本吧,首先需要利用Web资源功能新建一个JQuery的Web 资源,这个很多项目有我就不多说了。然后下载SURVEYJS,下载的比较大,3M多,我到 https://jscompress.com/ 网站将其压缩后只有 483k了(注意默认的压缩去掉了版权声明等注释,不符合使用协议,我这里没有时间去继续研究了),勉强可以,创建的Web资源如下:

因为还会用到它的一个css文件,我也上传下,如下图:

然后我用代码做个简单的例子吧,它支持多语言,这对于全球部署很重要,建立如下的Web资源来展示:

代码如下:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>罗勇测试SURVEYJS</title>
<script type="text/javascript" src="../../common/js/jquery.min.js"></script>
<script type="text/javascript" src="../../common/js/survey.jquery.min.js"></script>
<script src="../../../ClientGlobalContext.js.aspx" type="text/javascript"></script>
<link href="../../common/css/survey.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div id="surveyElement"></div>
<div id="surveyResult"></div>
<script type="text/javascript">
var mycustomSurveyStrings = {
pagePrevText: "My Page Prev",
pageNextText: "My Page Next",
completeText: "OK - Press to Complete",
};
Survey.surveyLocalization.locales["my"] = mycustomSurveyStrings;
Survey.StylesManager.applyTheme("default");
var json = {
title: "素格格新疆特产店调查问卷",
pages: [
{
title: "购买次数",
questions: [
{
type: "radiogroup", name: "buytime", isRequired: true, colCount: 3, title: "你在素格格新疆特产店购买过几次?",
choices: [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"9"
]
}
]
},
{
title: "出售产品",
questions: [
{
type: "checkbox", name: "products", title: "Plese select from the list",
colCount: 4, isRequired: true, title: "素格格新疆特产店主要出售哪些产品?",
choices: ["巴旦木", "碧根果", "葡萄干", "无花果", "纸皮核桃", "开心果", "葡萄酒", "牛肉干",
"奶酪", "纯牛奶", "香蕉牛奶", "天山乌梅", "蜂蜜", "青川黑木耳", "茶树菇", "香菇"]
}
]
},
{
title: "请告知我们你的姓名和邮箱",
questions: [
{ type: "text", name: "name", title: "姓名:" },
{ type: "text", name: "email", title: "邮箱:" }]
}]
}; window.survey = new Survey.Model(json);
survey.onComplete.add(function (result) {
document.querySelector('#surveyResult').innerHTML = "result: " + JSON.stringify(result.data);
var clientURL = GetGlobalContext().getClientUrl();
var req = new XMLHttpRequest()
req.open("POST", encodeURI(clientURL + "/api/data/v8.0/ly_tests"), 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 == 204) {
var testUri = this.getResponseHeader("OData-EntityId");
Xrm.Utility.alertDialog("创建成功的罗勇测试试题记录的URI: " + testUri)
}
else {
var error = JSON.parse(this.response).error;
Xrm.Utility.alertDialog("创建罗勇测试实体记录出错." + error.message);
}
}
};
var test = {};
test.ly_name = result.data.name;//单行文本
test.ly_optionset = 364750000 + Number(result.data.buytime);//选项集
test.ly_multilinetext = result.data.products.join('/');//多行文本
test.ly_singlelinetext = result.data.email;
req.send(JSON.stringify(test));
});
survey.locale = 'zh-cn';
$("#surveyElement").Survey({
model: survey
})
</script>
</body>
</html>
我这里让用户点击命令栏按钮执行如下代码来打开这个Web资源:
var recordId = Xrm.Page.data.entity.getId();
var recordType = Xrm.Page.data.entity.getEntityName();
var webResourceName = "ly_/test/page/SURVEYJSTest.html";
Xrm.Utility.openWebResource(webResourceName + "?typename=" + recordType + "&id=" + recordId, null, 800, 600);
效果如下图,可以看到默认的主题效果还是不错的:



我这里提交后利用填写的资料向CRM插入了一条记录:

插入记录的详情如下,可以看到插入记录的值是填写的值。

在Dynamics 365中使用SURVEYJS代替对话(Dialog)制作话术的更多相关文章
- 自定义工作流活动报错:您无法登陆系统。原因可能是您的用户记录或您所属的业务部门在Microsoft Dynamics 365中已被禁用。
本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复265或者20170926可方便获取本文,同时可以在第一间得到我发布的最新的博文信息,follow me!我的网站是 www.luoyong.me ...
- 将Dynamics 365中的用户及其角色、角色导出到Excel中
关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复240或者20161204可方便获取本文,同时可以在第一间得到我发布的最新的博文信息,follow me!我的网站是 www.luoyong. ...
- Dynamics 365中的应用程序介绍
本人微信和易信公众号:微软动态CRM专家罗勇 ,回复275或者20180630可方便获取本文,同时可以在第一间得到我发布的最新的博文信息,follow me!我的网站是 www.luoyong.me ...
- Dynamics 365中配置和使用文件夹级别的跟踪(folder-level tracking)
本人微信和易信公众号:微软动态CRM专家罗勇 ,回复274或者20180630可方便获取本文,同时可以在第一间得到我发布的最新的博文信息,follow me!我的网站是 www.luoyong.me ...
- Dynamics 365工作流报错:您无法登陆系统。原因可能是您的用户记录或您所属的业务部门在Microsoft Dynamics 365中已被禁用。
本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复265或者20170926可方便获取本文,同时可以在第一间得到我发布的最新的博文信息,follow me!我的网站是 www.luoyong.me ...
- Dynamics 365中开发和注册插件介绍
我是微软Dynamics 365 & Power Platform方面的工程师罗勇,也是2015年7月到2018年6月连续三年Dynamics CRM/Business Solutions方面 ...
- Dynamics 365中部分账号使用系统明显缓慢怎么办?先这么干!
摘要: 本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复263或者20170828可方便获取本文,同时可以在第一间得到我发布的最新的博文信息,follow me!我的网站是 www.luoyon ...
- Dynamics 365中自定义工作流活动获取的上下文分析及注意事项
关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复244或者20170306可方便获取本文,同时可以在第一间得到我发布的最新的博文信息,follow me!我的网站是 www.luoyong. ...
- Dynamics 365中的非交互式账号(Non-interactive User)介绍
摘要: 本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复272或者20180616可方便获取本文,同时可以在第一间得到我发布的最新的博文信息,follow me!我的网站是 www.luoyon ...
随机推荐
- aspnet core2中使用csp内容安全策略
aspnet core2中使用csp内容安全策略 问题:aspnet core2如何使用csp防止xss的攻击 方法: public void ConfigureServices( IServiceC ...
- [SQL]LeetCode196. 删除重复的电子邮箱 | Delete Duplicate Emails
Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...
- [Swift]LeetCode357. 计算各个位数不同的数字个数 | Count Numbers with Unique Digits
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
- [Swift]LeetCode514. 自由之路 | Freedom Trail
In the video game Fallout 4, the quest "Road to Freedom" requires players to reach a metal ...
- [Swift]LeetCode542. 01 矩阵 | 01 Matrix
Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell. The distance b ...
- 3-4 计算属性的setter和getter
Vue中的计算属性的setter和getter //如上,fullName这个方法在取这个数据的时候,会执行get中的方法:而在设置数据时,会执行set中的方法.其中set中有个参数(value),用 ...
- Python数据分析(一): ipython 技巧!
不一定非得使用Jupyter Notebook,试试ipython命令行 安装 ipython 我只试过Windows 10环境下的. 1.安装python安装包之后,应该就有ipython了. 2. ...
- Scala安装教程
首先去Java官网下载Java的安装包 jdk-8u121-windows-x64.exe 再去Scala官网下载Scala的安装包 Scala2.12.1 安装Java: 配置Java环境变量(系统 ...
- 初探React与D3的结合-或许是visualization的新突破?
自诞生之初截止目前(2016年初),React可以说是前端界最流行的话题,如果你还不知道React是何物,你就该需要充充电了. d3是由纽约时报工程师开源的一个绘制基于svg的数据可视化工具,是近几年 ...
- Eureka介绍
1. Eureka是什么 Eureka是一个基于REST的服务,主要用于AWS云中的定位服务,以实现中间层服务器的负载平衡和故障转移 在 Spring Cloud 微服务架构中通常用作注册中心 我们 ...