在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 ...
随机推荐
- MySQL乐观锁为什么可以防止并发
问题引入 本文介绍的是最常用的也是mysql默认的innoDB引擎 Read committed隔离级别下事物的并发.这种情况下的事物特点是 读:在一个事物里面的select语句 不会受到其他事物(不 ...
- Kali学习笔记42:SQL手工注入(4)
前三篇文章都是在讲发现SQL注入漏洞 如何查询得到所有的信息 那么另一条思路还未尝试过:能否修改数据? 例如这样: '; update users set user='yiqing' where us ...
- [Swift]LeetCode77. 组合 | Combinations
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. Example: I ...
- [Swift]LeetCode543. 二叉树的直径 | Diameter of Binary Tree
Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a b ...
- [Swift]LeetCode934. 最短的桥 | Shortest Bridge
In a given 2D binary array A, there are two islands. (An island is a 4-directionally connected grou ...
- [树莓派]启用root账户
树莓派使用的linux是debian系统,所以树莓派启用root和debian是相同的. debian里root账户默认没有密码,但账户锁定. 当需要root权限时,由默认账户经由sudo执行,Ras ...
- 什么是“闭包”(closure)为什么要用它?
什么是闭包: 闭包是指有权访问另一个函数作用域中变量的函数,创建闭包的最常见的方式就是在一个函数内创建另一个函数,通过另一个函数访问这个函数的局部变量,利用闭包可以突破作用链域,将函数内部的变量和方 ...
- web开发中获取的各种高度和宽度
前端开发中经常需要获取页面还有屏幕的高度和宽度进行计算,此文即介绍如何用 JavaScript 还有 jQuery 获取这些尺寸. 1.简介 一个页面显示在浏览器内,浏览器又放置在屏幕窗口内,所以由里 ...
- js的预解析
在ES6之前,变量使用var声明,会存在变量的预解析(函数也有预解析).ES6引了let和const,但是现阶段ES6并没有完全普及,而且很多比较老的代码都还是按照ES5的标准甚至是ES3的标准来书写 ...
- React 中的this.setState
在react中如何修改state中的数据 第一种写法:this.setState() 参数1:对象 需要修改的数据 参数2:回调 this.setState是一 ...