gpt4 book ai didi

dynamics-crm - 使用 javascript ex : prvOverridePriceEngineQuote (not a role) 检索用户是否具有特殊权限

转载 作者:行者123 更新时间:2023-12-04 03:11:48 27 4
gpt4 key购买 nike

我想知道用户是否有特殊权限“prvOverridePriceEngineQuote”,但我没有完成。

我的代码看起来像:

var userid = Xrm.Page.context.getUserId();
var userhasPrivilege;

var quoteFetchXML = "<fetch version=\"1.0\" output-format=\"xml-platform\" mapping=\"logical\" distinct=\"false\">" +
"<entity name=\"privilege\">" +
"<attribute name=\"name\" />" +
"<filter>" +
"<condition attribute=\"name\" operator=\"eq\" value=\"prvOverridePriceEngineQuote\" />" +
"</filter>" +
"<link-entity name=\"roleprivileges\" from=\"privilegeid\" to=\"privilegeid\">" +
"<link-entity name=\"role\" from=\"roleid\" to=\"roleid\">" +
"<link-entity name=\"systemuserroles\" from=\"roleid\" to=\"roleid\">" +
"<link-entity name=\"systemuser\" from=\"systemuserid\" to=\"systemuserid\">" +
"<filter>" +
"<condition attribute=\"systemuserid\" operator=\"eq\" value=\"" + userid + "\" />" +
"</filter>" +
"</link-entity>" +
"</link-entity>" +
"</link-entity>" +
"</link-entity>" +
"</entity>" +
"</fetch>";

var encodedFetchXML = encodeURIComponent(quoteFetchXML);

var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.0/accounts?fetchXml=" + encodedFetchXML, true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Prefer", "odata.include-annotations=\"OData.Community.Display.V1.FormattedValue\"");
req.onreadystatechange = function () {

if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var results = JSON.parse(this.response);
}
}
};
req.send();

当我在 XRMToolBox 中测试它时它工作正常,但当我在 Dynamics crm 中使用 javascript 运行代码时却没有。

我收到这个错误:

"Could not find a property named 'privilegeid' on type 'Microsoft.Dynamics.CRM.account'"

"{\r\n \"error\":{\r\n \"code\":\"\",\"message\":\"Could not find a property named 'privilegeid' on type 'Microsoft.Dynamics.CRM.account'.\",\"innererror\":{\r\n \"message\":\"Could not find a property named 'privilegeid' on type 'Microsoft.Dynamics.CRM.account'.\",\"type\":\"Microsoft.OData.Core.ODataException\",\"stacktrace\":\" at Microsoft.OData.Core.UriParser.Parsers.SelectPathSegmentTokenBinder.ConvertNonTypeTokenToSegment(PathSegmentToken tokenIn, IEdmModel model, IEdmStructuredType edmType, ODataUriResolver resolver)\r\n at Microsoft.OData.Core.UriParser.Visitors.SelectPropertyVisitor.ProcessTokenAsPath(NonSystemToken tokenIn)\r\n at Microsoft.OData.Core.UriParser.Visitors.SelectPropertyVisitor.Visit(NonSystemToken tokenIn)\r\n at Microsoft.OData.Core.UriParser.Parsers.SelectBinder.Bind(SelectToken tokenIn)\r\n at Microsoft.OData.Core.UriParser.Parsers.SelectExpandBinder.Bind(ExpandToken tokenIn)\r\n at Microsoft.OData.Core.UriParser.Parsers.SelectExpandSemanticBinder.Bind(IEdmStructuredType elementType, IEdmNavigationSource navigationSource, ExpandToken expandToken, SelectToken selectToken, ODataUriParserConfiguration configuration)\r\n at Microsoft.OData.Core.UriParser.ODataQueryOptionParser.ParseSelectAndExpandImplementation(String select, String expand, ODataUriParserConfiguration configuration, IEdmStructuredType elementType, IEdmNavigationSource navigationSource)\r\n at Microsoft.OData.Core.UriParser.ODataQueryOptionParser.ParseSelectAndExpand()\r\n at Microsoft.Crm.Extensibility.OData.EntityController.GetEntitySet(String entitySetName)\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.b__9(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()\"\r\n }\r\n }\r\n}"

你知道我做错了什么或者我该怎么做吗?

最佳答案

错误是因为您在帐户实体而不是权限实体上执行 FetchXML。

你需要改变这一行:

req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.0/accounts?fetchXml="

另一个:

req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.0/privileges?fetchXml="

关于dynamics-crm - 使用 javascript ex : prvOverridePriceEngineQuote (not a role) 检索用户是否具有特殊权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44654920/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com