1
votes

I am a newbie to CRM. Am trying to automate a process in CRM. But not sure how to check the value of CRM entity rows constantly and perform some post operations.

For example: Consider we have a CRM entity "account" and it has a field called "expiry date" so how to check the expiry date for all records in account entity and if the date is in the past or today's date change the "account" field status to inactive for the records that satisfy the conditions. Any insights will be helpful. Is there any way we can do this using CRM plugin? If yes, how to check all rows in account entity for the expiry date.

Any help would be much appreciated.

Thanks in advance.

2

2 Answers

3
votes

You could setup a workflow to trigger this: Set custom Workflow to run daily in CRM 2013

You could also run a scheduled task from Azure or a windows machine: Azure Service Bus Topic subscribe from CRM plugin

You could also use Bulk Delete Process to setup your own scheduler in CRM: http://www.crmsoftwareblog.com/2012/08/using-the-bulk-deletion-process-to-schedule-recurring-workflows/

0
votes

You could create an on-demand workflow that executes a custom workflow activity step and then times out for 24 hours. After the 24 hours has passed, the workflow could call itself as a child workflow (thus running your custom step every day).

The custom workflow activity would look something like this:

var query = new QueryExpression { EntityName = "account", ColumnSet = new ColumnSet(false) };

query.Criteria.AddCondition("statecode", ConditionOperator.Equal, 0);
query.Criteria.AddCondition("expiryDate", ConditionOperator.OnOrBefore, DateTime.Now);

var expiredAccounts = service.Retrieve(query);

foreach (var account in expiredAccounts.Entities) {
    var stateRequest = new SetStateRequest {
        EntityMoniker = account.ToEntityReference(),
        State = new OptionSetValue(1),
        Status = new OptionSetValue(1)
    };

    service.Execute(stateRequest);
}

Alternatively you could create a workflow which runs on creation of an account. The workflow would wait until the account's expiry date and then deactivate the account. This option is simpler but creates a larger performance overhead to your CRM application's async service.