Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Guidance on how to create a plugin to count the records of an entity (every 15 days)

(0) ShareShare
ReportReport
Posted on by

Hi everyone!

I m new in plugin development. I have followed some guidance by Microsoft and a sample script but i need guidance on how to create a plugin to count the service activities every 15 days.

Now the code i used using javascript is the one below , but i need to create a plugin to make that concurrent workflow :

var fetchXml =
"<fetch version='1.0' aggregate='true' >" +
  "<entity name='serviceappointment' >" +
     "<filter type='and' >" +
      "<condition attribute='scheduledstart' operator='next-month' />" +
    "</filter>" +
    "<attribute name='activityid' alias='count' aggregate='count' />" +
  "</entity>" +
"</fetch>" ;

	/*"<fetch mapping='logical' aggregate='true'>" +
            "<entity name='account'>" +
	    "<attribute name='accountid' aggregate='count' alias='count' />" +
	"</fetch>";*/

	var result = XrmServiceToolkit.Soap.Fetch(fetchXml, false);
	if((result) && (result.length) && (result.length > 0)) {
	    var count = result[0].attributes['count'].value;
	}
	// Something is wrong
	return -1;
}


So i found this code on Microsoft : 

// *****************************************************************************************************************
//                FetchXML      opportunity_count   Aggregate 2
// *****************************************************************************************************************
// Fetch the count of all opportunities.  This is the equivalent of
// SELECT COUNT(*) AS opportunity_count ... in SQL.
string opportunity_count = @" 
<fetch distinct='false' mapping='logical' aggregate='true'> 
    <entity name='opportunity'> 
       <attribute name='name' alias='opportunity_count' aggregate='count'/> 
    </entity> 
</fetch>";

EntityCollection opportunity_count_result = _serviceProxy.RetrieveMultiple(new FetchExpression(opportunity_count));

foreach (var c in opportunity_count_result.Entities)
{
    Int32 aggregate2 = (Int32)((AliasedValue)c["opportunity_count"]).Value;
    System.Console.WriteLine("Count of all opportunities: " + aggregate2); 

}
System.Console.WriteLine("===============================");


Shouldn't i get run the exectute function like in one of the sample plugins i read ? Also where this workflow should run , i don't want it to run on record creation or update. I just want it to run globally every 15 days and target Service Activities through the fetchxml. And how a custom workflow activity can be executed every 15 days?

Thanks a lot and sorry for the noobish questions!

*This post is locked for comments

  • RE: Guidance on how to create a plugin to count the records of an entity (every 15 days)

    Hi,

    you can use following trick for this.

    if you are using online environment then you can create MS flow for this. you can schedule that flow on recurrence of 15 days.for this, create a custom entity in CRM. In Flow ,create a record in custom entity and write a plugin on Create Message of custom entity and do your code in that. In this way you will also find Execute method there.

  • Suggested answer
    RE: Guidance on how to create a plugin to count the records of an entity (every 15 days)

    You can use Timeout function to schedule a workflow.

    www.powerobjects.com/.../setting-up-recurring-workflows-in-dynamics-crm-2016

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,407 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans