我想知道一个用户是否有特殊权限“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运行代码时却没有。
我收到此错误:
“无法在类型'Microsoft.Dynamics.CRM.account'上找到名为'privilegeid'的属性”
“{\ r \ n \”错误\“:{\ r \ n \”代码\“:\”\“,\”message \“:\”无法在类型上找到名为'privilegeid'的属性'Microsoft.Dynamics.CRM.account'。\“,\”innererror \“:{\ r \ n \”message \“:\”无法在类型'Microsoft.Dynamics.CRM上找到名为'privilegeid'的属性。帐户'。\“,\”键入\“:\”Microsoft.OData.Core.ODataException \“,\”stacktrace \“:\”at Microsoft.OData.Core.UriParser.Parsers.SelectPathSegmentTokenBinder.ConvertNonTypeTokenToSegment(PathSegmentToken tokenIn, IE.mModel模型,IEdmStructuredType edmType,ODataUriResolver解析器)\ r \ n在Microsoft.OData.Core.UriParser.Visitors.SelectPropertyVisitor.ProcessTokenAsPath(NonSystemToken tokenIn)\ r \ n在Microsoft.OData.Core.UriParser.Visitors.SelectPropertyVisitor.Visit(在Microsoft.OData.Core.UriParser.Parsers.SelectExpandBinder.Bind(ExpandToken tokenIn)\ r \的Microsoft.OData.Core.UriParser.Parsers.SelectBinder.Bind(SelectToken tokenIn)\ r \ n中的NonSystemToken tokenIn)\ r \ n n在Microsoft.OData.Core.UriParser.Parsers.SelectExpand SemanticBinder.Bind(IEdmStructuredType elementType,IEdmNavigationSource navigationSource,ExpandToken expandToken,SelectToken selectToken,ODataUriParserConfiguration配置)\ r \ n在Microsoft.OData.Core.UriParser.ODataQueryOptionParser.ParseSelectAndExpandImplementation(字符串选择,字符串展开,ODataUriParserConfiguration配置,IEdmStructuredType elementType,IEdmNavigationSource navigationSource )\ r \ n在Microsoft.OData.Core.UriParser.ODataQueryOptionParser.ParseSelectAndExpand()\ r \ n在Microsoft.Crm.Extensibility.OData.EntityController.GetEntitySet(String entitySetName)\ r \ n在lambda_method(Closure,Object,对象[])\ r \ n在System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor。&lt;&gt; c__DisplayClass10.b__9(对象实例,Object [] methodParameters)\ r \ n在System.Web.Http.Controllers上。 ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext,IDictionary`2参数,CancellationToken cancellationToken) r \ n ---从抛出异常的上一个位置开始的堆栈跟踪结束---在System.Runtime.CompilerServices.TaskAwaiter的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)\ r \ n中的\ r \ n \ n \ n \ n .HandleNonSuccessAndDebuggerNotification(任务任务)\ r \ n在System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext()\ r \ n ---从前一个引发异常的位置的堆栈跟踪结束--- \ r \ n System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)\ r \ n,位于System.Web.Http.Controllers.ActionFilterResult.d__2的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)\ r \ n。 MoveNext()\ r \ n ---从抛出异常的上一个位置开始的堆栈跟踪结束---在System.Runtime上的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)\ r \ n中的\ r \ n \ n \ n \ n System.Web.Http.Dispatcher.HttpControl中的.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)\ r \ n lerDispatcher.d__1.MoveNext()\“\ r \ n} \ r \ n} \ r \ n}”
你知道我做错了什么或我怎么做?
答案 0 :(得分:1)
导致错误的原因是您在帐户实体上执行FetchXML而不是权限实体。
您需要更改此行:
T1
另一个人:
req.open(“GET”, Xrm.Page.context.getClientUrl() + “/api/data/v8.0/accounts?fetchXml=”