web
You’re offline. This is a read only version of the page.
close
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

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    You can use Timeout function to schedule a workflow.

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

  • Community Member Profile Picture
    on at

    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.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans