I'm retrieving all privileges for a user with RetrieveUserPrivilegesRequest.
This works fine, and I get all privileges assigned to a certain user.
In addition I would need to know the origin of each of those privileges. Meaning that I want to know from which SecurityRole (can be multiple) every privilege derives. In the next step I would need to know if the SecurityRole is directly assigned to the user or if it derives from a Team the user is part of.
Any help would be much appreciated!
You can make this and it should work.
The relashionship goes in this way:
privilege --> privilege.role <-- role --> role.user <-- user.
and
privilege --> privilege.role <-- role --> role.team <-- team --> team.user <-- user
So with this, I will show you with fetchXml, you can use LinQ or QE. You need to ask, first which are the roles the user have:
<fetch mapping="logical" count="50" version="1.0">
<entity name="role">
<attribute name="roleid" />
<link-entity name="systemuserroles" from="roleid" to="roleid">
<link-entity name="systemuser" from="systemuserid" to="systemuserid">
<filter>
<condition attribute="systemuserid" operator="eq" value="{YOUR-USER-GUID}" />
</filter>
</link-entity>
</link-entity>
</entity>
</fetch>
Now you have the user's roles, with those, for each rol, you ask what privileges the user have.
<fetch mapping="logical" count="50" version="1.0">
<entity name="privilege">
<attribute name="privilegeid" />
<link-entity name="roleprivileges" from="privilegeid" to="privilegeid">
<link-entity name="role" from="roleid" to="roleid">
<filter>
<condition attribute="roleid" operator="eq" value="{THE-ROLE-GUID}" />
</filter>
<link-entity name="systemuserroles" from="roleid" to="roleid">
<link-entity name="systemuser" from="systemuserid" to="systemuserid">
<filter>
<condition attribute="systemuserid" operator="eq" value="{FOREACH-YOUR-GUID}" />
</filter>
</link-entity>
</link-entity>
</link-entity>
</link-entity>
</entity>
</fetch>
If you need to know the privileges the team have, then you need to query against the team, because the team is the owner of the roles.
First the teams the user belongs to:
<fetch mapping="logical" count="50" version="1.0">
<entity name="team">
<attribute name="teamid" />
<link-entity name="teammembership" from="teamid" to="teamid">
<link-entity name="systemuser" from="systemuserid" to="systemuserid">
<filter>
<condition attribute="systemuserid" operator="eq" value="{YOUR-USER-GUID}" />
</filter>
</link-entity>
</link-entity>
</entity>
</fetch>
And then, for each team the user belongs to, ask for the roles the teams have:
<fetch mapping="logical" count="50" version="1.0">
<entity name="role">
<attribute name="roleid" />
<link-entity name="teamroles" from="roleid" to="roleid">
<link-entity name="team" from="teamid" to="teamid">
<filter>
<condition attribute="teamid" operator="eq" value="{YOUR-TEAM-GUID" />
</filter>
</link-entity>
</link-entity>
</entity>
</fetch>
I will like to know, why are you trying to do this, because it may be a better approach, because this is quite heavy, if you need to know anything else just let me know, hope this can help you.
Related
Trying to create a FetchXML report for CRM 2016 using VS2012 following instructions here: Create a new report using SQL Server Data Tools. I want to simply find a count of cases created between two dates.
The instructions talk about copy/pasting downloaded FetchXML from the CRM Advanced find process.
FetchXML generated by the Advanced Find process to list all Cases (by ticketnumber):
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
<entity name="incident">
<attribute name="incidentid" />
<attribute name="ticketnumber" />
<order attribute="ticketnumber" descending="false" />
<filter type="and">
<filter type="and">
<condition attribute="createdon" operator="on-or-after" value="2015-07-01" />
<condition attribute="createdon" operator="on-or-before" value="2016-06-30" />
</filter>
</filter>
</entity>
</fetch>
I can't find a way to aggregate with Advanced Find, but instructions here: Use FetchXML aggregation seem to indicate a couple of attribute changes to the XML is all that is necessary.
So, I changed my FetchXML in notepad++ to:
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" aggregate="true" >
<entity name="incident">
<attribute name="incidentid" />
<attribute name="ticketnumber" aggregate="count" alias="casecount" />
<order attribute="ticketnumber" descending="false" />
<filter type="and">
<filter type="and">
<condition attribute="createdon" operator="on-or-after" value="2015-07-01" />
<condition attribute="createdon" operator="on-or-before" value="2016-06-30" />
</filter>
</filter>
</entity>
</fetch>
This results in an error:
Either I'm doing something wrong, or that FetchXML Aggregation page is incorrect.
Can someone show me how to create a fetchXML report that counts cases opened between two dates?
You cannot select an attribute (incidentid) while at the same time doing aggregation.
Additionally, applying ordering does not make sense when you are aggregating.
I have removed those two lines, after which the FetchXML is able to run:
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" aggregate="true" >
<entity name="incident">
<attribute name="ticketnumber" aggregate="count" alias="casecount" />
<filter type="and">
<filter type="and">
<condition attribute="createdon" operator="on-or-after" value="2015-07-01" />
<condition attribute="createdon" operator="on-or-before" value="2016-06-30" />
</filter>
</filter>
</entity>
</fetch>
As a side-note, you might want to use the FetchXml Tester in XrmToolBox for quickly being able to edit and execute FetchXML.
Use this for order by clause
<order alias="casecount" descending="true" />
I am working on creation of report for "No open activities on Accounts of type Phone call" in advance find. I am able to get list of accounts with completed activities of type phone call but not accounts with no activities at all.
I tried assigning Activity type and subject to does not contain data, it still does not fetch accounts with no activities.
In below picture, you will see filters I have used,
No Open Activity image
You should try using query like following:
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
<entity name="account">
<attribute name="name" />
<attribute name="primarycontactid" />
<attribute name="telephone1" />
<attribute name="accountid" />
<order attribute="name" descending="false" />
<link-entity name="activityparty" from="partyid" to="accountid" alias="ae" link-type="outer">
<link-entity name="activitypointer" from="activityid" to="activityid" alias="af" link-type="outer">
<filter type="and">
<condition attribute="activitytypecode" operator="eq" value="4210" />
</filter>
</link-entity>
</link-entity>
<filter type="and">
<condition entityname="af" attribute="activityid" operator="null" />
</filter>
</entity>
</fetch>
Code is based on following article - https://msdn.microsoft.com/en-us/library/dn531006.aspx
Left outer joins aren't supported in Advanced Find. You will have to use a custom query like the one Andrii posted.
EDIT: If you want to run your report with custom fetchXml maybe using the Reporting Authoring extensions for SQL Server Data tools. You could copy & paste your fetchXml there and then upload the report into CRM.
I am using CRM 2011 on-Premisis. I have a portal in which client create a ticket(task in crm) and it goes in specific queue line (CS Queue,EDI Queue, Lab Quue). But some tasks created but do not goes in any quue. How I get these taks which are not in any queue.
If anyone have an idea please share with me.
Thanks in advance.
Regards,
Riaz Usmani
I believe you can try to use Left Outer Join to get your data. I've built provided query based on following article - http://msdn.microsoft.com/en-us/library/dn531006.aspx Try it:
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
<entity name="task">
<attribute name="activityid" />
<attribute name="subject" />
<link-entity name="queueitem" from="objectid" to="activityid" alias="ab" link-type="outer">
<attribute name="objectid" />
</link-entity>
<filter type="and">
<condition entityname="ab" attribute="objectid" operator="null" />
</filter>
</entity>
<fetch/>
I'm retrieving a list of all privileges from CRM:
QueryExpression q = new QueryExpression("privilege") {ColumnSet = new ColumnSet(true)};
var list = service.RetrieveMultiple(q).Entities;
This works fine.
I would now like to know the entity-name every privilege applies to. I.e. the privilege "prvDeleteNote" applies to the entity "Note".
This is no problem querying the database with SQL directly, but I would much prefer to retrieve the information from a service.
Cheers
As far as I know privilege entity doesn't have a property to identity the related entity.
As it turns out, this FetchXML returns what I was looking for:
<fetch mapping=""logical"" version=""1.0"">
<entity name=""privilege"">
<attribute name=""privilegeid"" />
<attribute name=""name"" />
<attribute name=""canbelocal"" />
<attribute name=""canbedeep"" />
<attribute name=""canbeglobal"" />
<attribute name=""canbebasic"" />
<link-entity name=""privilegeobjecttypecodes"" from=""privilegeid"" to=""privilegeid"" link-type=""outer"" alias=""otc"">
<attribute name=""objecttypecode"" />
</link-entity>
</entity>
</fetch>
I can access the Type with:
((AliasedValue)privilegeEntity.Attributes["otc.objecttypecode"]).Value.ToString()
where privilegeEntity is one entity from the response.
I was expecting the int value ObjectTypeCode, and was suprised that it returns the name of the entity.
I am having a bizarre problem, and was hoping that someone could shed some light on why it is occurring. If I Query dynamics using FetchXML using the following:
<fetch mapping="logical" count="10" distinct="true" version="1.0">
<entity name="activitypointer">
<attribute name="activityid" />
<attribute name="activitytypecode" />
<attribute name="createdon" />
<attribute name="ownerid" />
<attribute name="statecode" />
<attribute name="statuscode" />
<attribute name="subject" />
<attribute name="actualend" />
<order attribute="actualend" descending="true" />
<filter type="or">
<condition attribute="regardingobjectid" operator="eq" value="66431c2f-fab6-dd11-94f2-0014221f6f5c" />
</filter>
</entity>
Then I get the following set of results:
However if I do the same query in SQL:
SELECT TOP 100 activityid, activitytypecodename, createdon, owneridname, statecodename, statuscodename, subject, actualend FROM [CRM2011_MSCRM].[dbo].[FilteredActivityPointer] WHERE regardingobjectid = '66431C2F-FAB6-DD11-94F2-0014221F6F5C' ORDER BY actualend DESC
Then I get the following results:
You can see that the results are pretty much the same, however if you look at the status code column then you can see that the results differ in the fact that one states that it has been sent while the other has been completed.
Therefore how can I filter based upon the status of the item when the two different methods seem to bring back different results for the state code?
(I am currently trying to do a report in SSRS using FetchXML I have previously tried doing it in SQL but had problems, therefore used FetchXML to solve this)
-- Edit
When I use the appointment entity then I do get the correct results:
<fetch mapping="logical" count="50" version="1.0">
<entity name="appointment">
<attribute name="activityid" />
<attribute name="activitytypecode" />
<attribute name="actualend" />
<attribute name="createdon" />
<attribute name="ownerid" />
<attribute name="statecode" />
<attribute name="statuscode" />
<attribute name="subject" />
<filter>
<condition attribute="regardingobjectid" operator="eq" value="66431c2f-fab6-dd11-94f2-0014221f6f5c" />
</filter>
</entity>
Which returns this:
The only problem with this though is I need to know the status for a whole list of different activities - thus I thought you needed to use the activity pointer (as it is the base class plus you can't join results together in SSRS.)
Well, this isn't an answer on how to solve this, perhaps, but I think I can shed some light on why it may be happening.
For the statuscode of an activitypointer, fetchXML is taking the integer value and mapping it to the activitypointer lookup table, while SQL maps it to the actual child entity's table.
For example, take your very first record, which happens to be an email. FetchXML says the status is "cancelled". Checking the activitypointer metadata (http://msdn.microsoft.com/en-us/library/gg328148.aspx) we see that "cancelled" is value "3". Now, going to the email entity metadata (http://msdn.microsoft.com/en-us/library/hh155312.aspx) we see that value "3" is actually "sent", which is what SQL says.
This goes for all the entities you have in the table. The lonely Task with no fetchXML status, for example, is actually completed according to sql. That's value "5" (http://msdn.microsoft.com/en-us/library/gg594424.aspx), which doesn't map to anything for activitypointers; their values are limited to a range of 1-4. As a result, fetchXML shows nothing.
Try getting the statuscodeValue rather than name. I expect the integer values will be identical for both fetchXML and SQL. Why they map the names differently I can't answer.