简体   繁体   中英

How to constantly check a value in CRM entity and perform some actions?

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.

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/

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM