检索用户是否具有使用 javascript 的特殊权限,例如:prvOverridePriceEngineQuote(不是角色)
retrieve if a user has a special privilege using javascript ex: prvOverridePriceEngineQuote (not a role)
我想知道用户是否有特殊权限"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="
我想知道用户是否有特殊权限"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="