Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7069755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:29:04+00:00 2026-05-28T05:29:04+00:00

We had an issue where our workflows have not been creating activities. I now

  • 0

We had an issue where our workflows have not been creating activities.

I now need to report which accounts have not had their workflows invoked.

I’ve tried advanced find and then moved to sql.

My question is can someone provide a simple starter query to pull which ‘entity’ has NOT had a specific activity associated with it?

Please let me know if the question is not clear enough or more info, is needed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:29:04+00:00Added an answer on May 28, 2026 at 5:29 am

    Below is a solution using SQL where I step through my thought process, and below that is a solution that gets started with the C# API (edit: just realized this is for a report, so that part can be disregarded). I’ve commented in most places, so I hope my methods are fairly straightforward.

    SQL

    1.

    --get all the entities that aren't activities and aren't intersect entities (N:N tables)
    --Put in your own where conditions to further filter this list,
    --which is still probably far too expansive
    SELECT
        A.name EntityName
    FROM MetadataSchema.Entity A
    WHERE 
        A.IsActivity = 0
            AND A.IsIntersect = 0
    

    2.

    --CROSS JOIN the non-activity entities with the activity entities
    --to get a list of all possible entity/activity pairings
    SELECT DISTINCT
        A.name EntityName
        , B.Name ActivityName
    FROM MetadataSchema.Entity A
        CROSS JOIN MetadataSchema.Entity B
    WHERE 
        A.IsActivity = 0
            AND A.IsIntersect = 0
            AND B.IsActivity = 1
    

    3.

    --LEFT JOIN the partial cartesian join above against the Activity table,
    --making a note of which entities actually have activity records.
    --This will provide a complete list of which entity/activity pairings
    --exist and don't exist
    SELECT
        A.name EntityName
        , B.Name ActivityName
        --if there is a matching activity, the unique key,
        --ActivityTypeCode (int), will be positive.
        --So, if there is a positive sum for an entity/activity
        --pairing, you know there is a valid pair; otherwise
        --no pair
        , CAST(CASE WHEN sum(coalesce(C.ActivityTypeCode, 0)) > 0
            THEN 1
        ELSE 0
        END AS BIT) EntityOwnsActivity  
    FROM MetadataSchema.Entity A
        CROSS JOIN MetadataSchema.Entity B
        LEFT JOIN dbo.ActivityPointer C ON
            --ObjectTypeCode is a unique identifier for Entities;
            --RegardingObjectTypeCode is the code for the entity type
            --associated with a particular activity
            A.ObjectTypeCode = C.RegardingObjectTypeCode
            --ActivityTypeCode is the code for the particular activity
                AND B.ObjectTypeCode = C.ActivityTypeCode
    WHERE 
        A.IsActivity = 0
            AND A.IsIntersect = 0
            AND B.IsActivity = 1
    GROUP BY 
        A.name
        , B.Name
    

    4.

    --Putting it all together, using the above master table,
    --filter out the entities/activities you're interested in
    --(in this case, all entities that aren't associated with
    --any emails)
    SELECT 
        EntityName
    FROM
    (
        SELECT
            A.name EntityName
            , B.Name ActivityName
            , CAST(CASE WHEN sum(coalesce(C.ActivityTypeCode, 0)) > 0
                THEN 1
            ELSE 0
            END AS BIT) EntityOwnsActivity  
        FROM MetadataSchema.Entity A
            CROSS JOIN MetadataSchema.Entity B
            LEFT JOIN dbo.ActivityPointer C ON
                A.ObjectTypeCode = C.RegardingObjectTypeCode
                    AND B.ObjectTypeCode = C.ActivityTypeCode
        WHERE 
            A.IsActivity = 0
                AND A.IsIntersect = 0
                AND B.IsActivity = 1
        GROUP BY 
            A.name
            , B.Name
    ) EntityActivities
    WHERE ActivityName = 'Email'
        AND EntityOwnsActivity = 0
    ORDER BY
        EntityName
    

    C#.NET API

    using (OrganizationServiceProxy _serviceProxy = 
            new OrganizationServiceProxy(
            new Uri(".../XRMServices/2011/Organization.svc"), null, null, null))
    {
        _serviceProxy.EnableProxyTypes();
    
        RetrieveAllEntitiesRequest request = new RetrieveAllEntitiesRequest()
        {
            EntityFilters = EntityFilters.Entity,
            RetrieveAsIfPublished = true
        };
    
        // Retrieve the MetaData.
        EntityMetadata[] entities = 
                ((RetrieveAllEntitiesResponse)_serviceProxy.Execute(request)).EntityMetadata;
    
        var ents = from e1 in entities.Where(x => x.IsActivity != true)
                                      .Where(x => x.IsIntersect != true)
                   from e2 in entities.Where(x => x.IsActivity == true)
                   select new
                   {
                       entityName = e1.SchemaName
                       ,
                       activityName = e2.SchemaName
                   };
        //at this point, because of the limited nature of the Linq provider for left joins
        //and sums, probably the best approach is to do a fetch query on each entity/activity
        //combo, do some sort of sum and find out which combos have matches
        // in the activity pointer table
    
        //API = very inefficient; maybe improved in next CRM release? Let's hope so!
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about joins in NHIBERNATE. We had an issue with our
We are about to issue version 4.0 of our iPhone app and have had
For months we have been struggling with a weird issue on 1 of our
I had an issue with my search not return the results I expect. I
I've consistently had an issue with parsing XML with PHP and not really found
(Jeopardy-style question, I wish the answer had been online when I had this issue)
I am having trouble with the following SQL statement. I have had this issue
Ok, I have a question relating to an issue I've previously had. I know
At our company's Xmas party we had almost a physical fight over one issue:
We recently had an issue where TortoiseSVN or AnkhSVN (I can't determine which) crashed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.