- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我猜这段代码可以在表单上正常工作。当我在 HTML 网络资源中处理 javascript 时,我似乎总是遇到 Xrm.Page.Context
和 getServerUrl
等方法的问题。
这是我要运行的函数:
function getAttributeOptions(entityLogicalName, attributeLogicalName, dictionaryObject, onComplete) {
///<summary>
/// <para>Retrieves the picklist attribute options and appends them to a dictionary object.</para>
/// <para>It then executes the function assigned to the onComplete parameter.</para>
///</summary>
///<param name="entityLogicalName" type="String">
/// The logical name of the entity
///</param>
///<param name="attributeLogicalName" type="String">
/// The logical name of the Picklist attribute
///</param>
///<param name="dictionaryObject" type="Object">
/// An empty object that will become a dictionary for the option values.
///</param>
///<param name="onComplete" type="Function">
/// A function to perform when the options are assigned to the dictionaryObject;
///</param>
if (!(typeof entityLogicalName == "string")) {
throw new Error("getAttributeOptions entityLogicalName parameter is required and must be a string.");
}
if (!(typeof attributeLogicalName == "string")) {
throw new Error("getAttributeOptions attributeLogicalName parameter is required and must be a string.");
}
if (!(typeof dictionaryObject == "object")) {
throw new Error("getAttributeOptions dictionaryObject parameter is required and must be an object.");
}
if (!(typeof onComplete == "function")) {
throw new Error("getAttributeOptions onComplete parameter is required and must be a function.");
}
var passThroughObject = {};
passThroughObject.eln = entityLogicalName;
passThroughObject.aln = attributeLogicalName;
passThroughObject.dObj = dictionaryObject;
passThroughObject.oc = onComplete;
if ((typeof SDK == "undefined") || (typeof SDK.Metadata == "undefined") || (typeof SDK.Metadata.Query == "undefined")) {
throw new Error("getAttributeOptions function requires the SDK.Metadata.Query.min.js library and it is not present.");
}
var mdq = SDK.Metadata.Query;
var semp = mdq.SearchableEntityMetadataProperties;
var samp = mdq.SearchableAttributeMetadataProperties;
var srmp = mdq.SearchableRelationshipMetadataProperties
var emp = mdq.EntityMetadataProperties;
var amp = mdq.AttributeMetadataProperties;
var rmp = mdq.RelationshipMetadataProperties;
var ve = mdq.ValueEnums;
//EntityFilter
var ef = new mdq.MetadataFilterExpression(mdq.LogicalOperator.And);
ef.addCondition(semp.LogicalName, mdq.MetadataConditionOperator.Equals, entityLogicalName);
//Entity Properties
var ep = new mdq.MetadataPropertiesExpression(false, [emp.Attributes]);
//Attribute Filter
var af = new mdq.MetadataFilterExpression(mdq.LogicalOperator.And);
af.addCondition(samp.LogicalName, mdq.MetadataConditionOperator.Equals, attributeLogicalName);
//Attribute Properties
var ap = new mdq.MetadataPropertiesExpression(false, [amp.OptionSet, amp.AttributeType]);
// AttributeQuery
var aq = new mdq.AttributeQueryExpression(af, ap);
// LabelQuery
var lq = new mdq.LabelQueryExpression([1033]);
//EntityQueryExpression
var eqe = new mdq.EntityQueryExpression(ef, ep, aq, null, lq);
//RetrieveMetadataChangesRequest
var rmcr = new mdq.RetrieveMetadataChangesRequest(eqe, null, mdq.DeletedMetadataFilters.Default);
mdq.RetrieveMetadataChanges(
rmcr,
function(rmcResponse, pto) {
var attributeType = "unknown";
if (typeof rmcResponse.EntityMetadata[0] == "undefined" || rmcResponse.EntityMetadata[0] == null) {
throw new Error("No entity metadata found for " + pto.eln);
}
if (typeof rmcResponse.EntityMetadata[0].Attributes[0] == "undefined" || rmcResponse.EntityMetadata[0].Attributes[0] == null) {
throw new Error("No attribute metadata found for " + pto.eln + "." + pto.aln);
}
if (typeof rmcResponse.EntityMetadata[0].Attributes[0].OptionSet == "undefined" || rmcResponse.EntityMetadata[0].Attributes[0].OptionSet == null) {
throw new Error(pto.eln + "." + pto.aln + " does not have an OptionSet property.");
}
attributeType = rmcResponse.EntityMetadata[0].Attributes[0].AttributeType;
if (attributeType != "Boolean") {
if (typeof rmcResponse.EntityMetadata[0].Attributes[0].OptionSet.Options == "undefined" || rmcResponse.EntityMetadata[0].Attributes[0].OptionSet.Options == null) {
throw new Error(pto.eln + "." + pto.aln + "OptionSet does not have an Options property");
}
if (typeof rmcResponse.EntityMetadata[0].Attributes[0].OptionSet.Options[0] == "undefined" || rmcResponse.EntityMetadata[0].Attributes[0].OptionSet.Options[0] == null) {
throw new Error(pto.eln + "." + pto.aln + "OptionSet.Options does not have any options");
}
}
pto.dObj[pto.eln] = pto.dObj[pto.eln] || {};
pto.dObj[pto.eln].attributes = pto.dObj[pto.eln].attributes || {};
pto.dObj[pto.eln].attributes[pto.aln] = pto.dObj[pto.eln].attributes[pto.aln] || {};
pto.dObj[pto.eln].attributes[pto.aln].options = pto.dObj[pto.eln].attributes[pto.aln].options || {};
if (attributeType != "Boolean") {
for (var i in rmcResponse.EntityMetadata[0].Attributes[0].OptionSet.Options) {
var option = rmcResponse.EntityMetadata[0].Attributes[0].OptionSet.Options[i];
pto.dObj[pto.eln].attributes[pto.aln].options[option.Value] = option.Label.UserLocalizedLabel.Label;
}
} else {
pto.dObj[pto.eln].attributes[pto.aln].options[0] = rmcResponse.EntityMetadata[0].Attributes[0].OptionSet.FalseOption.Label.UserLocalizedLabel.Label;
pto.dObj[pto.eln].attributes[pto.aln].options[1] = rmcResponse.EntityMetadata[0].Attributes[0].OptionSet.TrueOption.Label.UserLocalizedLabel.Label;
}
pto.oc(pto.eln, pto.aln);
},
function(error) {
writeMessage(error.message);
},
passThroughObject);
}
// MetaDataDictionary
var mdd = {};
function testResults(entityLogicalName, attributeLogicalName) {
alert("Options for " + entityLogicalName + "." + attributeLogicalName + " cached.");
}
getAttributeOptions("contact", "statecode", mdd, testResults);
for (option in mdd.contact.attributes.statecode.options) {
var value = option;
var label = mdd.contact.attributes.statecode.options[option];
alert(label);
}
这是我正在使用的库中有问题的部分:
function u() {
var n = "Context is not available.";
return typeof GetGlobalContext != "undefined" ? GetGlobalContext() : typeof Xrm != "undefined" ? Xrm.Page.context : new Error(n)
}
function h() {
var n = u().getServerUrl();
return n.match(/\/$/) && (n = n.substring(0, n.length - 1)), typeof u().getClientUrl != "undefined" && (n = u().getClientUrl()), n
}
这是我的错误:
我非常希望可以使用 getServerUrl
和 getClientUrl
。我该怎么做才能实现这一目标?
最佳答案
验证路径并将此库添加到您的 HTML 网络资源中以访问 CRM 上下文。
<script type="text/javascript" src="ClientGlobalContext.js.aspx"></script>
When you need context information outside a form, include a reference to the ClientGlobalContext.js.aspx page in an HTML web resource.
getServerUrl
也是 deprecated ,您必须根据您的 CRM 版本使用 getClientUrl
。
关于javascript - Uncaught TypeError : u(. ..).getServerUrl 不是 HTML Web 资源中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46137775/
你好我是 Angular JS 的初学者,当我开始创建模块和 Controller 时,我无法打印我的消息,下面是我的代码 var myModule = angular.module("myFirst
我对 JQuery 还是个新手,我正在尝试使用它遍历 JSON 数组并使用数组中的数据更新我的网页。 JSON 文件如下所示: [ { "firstname":"John",
我正在使用 AngularJS 1.3.5,我正在尝试从 json 文件中获取信息。这是我的代码:HTML 文件: {{da
我正在创建 Bootstrap 模板。我收到两个错误,我不知道自己做错了什么。当我搜索类似的问题时,似乎是脚本错乱了,但我认为它们的位置是正确的。 两个错误: 未捕获的 ReferenceError:
我试图用子菜单制作导航栏,但我一直收到 dropMenu 未定义,当我将鼠标悬停在两个巴黎链接上时,我收到 Uncaught TypeError: Cannot read property 'styl
我正在尝试在名为 UserComponent 的 Angular 组件上运行 karma 测试。在此组件中,我有一个 ngOnInit 执行此操作: ngOnInit() { const
当我启用 login.spec.ts 测试时,对于不同的测试,我总是随机收到此错误。未捕获错误:未捕获( promise ):错误:无法匹配任何路由。 URL 段:“注销” 我尝试使用以下方法伪造 a
自从我设置一个与 Angular 一起运行的网络应用程序以来已经有一段时间了。我正在通过一个旧项目回顾我的步骤(尝试在我正在做的页面上实现一个 Controller ,确保 Controller 文件
在 AWS Elastic Beanstalk 上部署应用程序后会发生此错误。构建和部署成功,所有模块都正常工作,除了一个显示上述 super 表达式错误的模块。一切似乎都在本地机器上正常工作,甚至可
我刚刚开始使用 Node.js 并尝试使用模块。我已经安装了 Node 和 npm,并确保一切顺利。我将在下面添加代码来向您展示我得到了什么。 我有两个 js 文件,它们在这里。 app.js: va
在 Android 4.4.2 KitKat (API 19) 模拟器上运行时,我的代码出现问题... 当我在 Android 4.3 (API 18) 模拟器上模拟我的项目时,它正常工作并使用 Ma
function more(){ var MoreDetails = document.getElementById('MoreDetails'); More
我正在练习 Javascript,并且有以下代码,该代码在 sets[i][j] = initial_sets [i ][j]; 行。这个想法似乎是正确的,但我不明白为什么会出现错误。 var set
$(document).ready(function(){ $('#name').val('Name1'); }); function clickMe(){ console.lo
我正在创建一个网络应用程序,但我遇到了一个无法解决的简单问题。我已将产生问题的代码放在这里:http://jsfiddle.net/rkumarnirmal/5w3FG/ 应该显示此答案的第二个ale
我正在执行一项长时间运行的任务,在中间的某个位置,可能会抛出此异常: Uncaught DOMException: Blocked a frame with origin "http://localh
我试图通过使用 HTML5 中的 onEnded 属性一首接一首地播放 3 首歌曲。这是我的第一次尝试,但出现错误。 错误: Uncaught ReferenceError: src is not d
检查 Fiddle 以查看发生的故障。 当我将数据(即使我将其留空)添加到文本框并尝试单击“添加”时,它没有执行任何操作。 打开 Chrome 和 Firefox 控制台都给我同样的错误,它说“cha
这个问题在这里已经有了答案: How to access the correct `this` inside a callback (13 个回答) 关闭5年前。 您好,这是我的(快捷方式)示例代码:
我正在处理一个项目,每次 Node 运行我的代码时,浏览器控制台都会给我这个: Uncaught TypeError: Failed to resolve module specifier "expr
我是一名优秀的程序员,十分优秀!