-
Notifications
You must be signed in to change notification settings - Fork 15
Tutorial 5
PhuocLe edited this page Aug 26, 2018
·
10 revisions
- When lead created, send an email (with an email template) notification to all team members of the current user belong to teams
- Finish Tutorial 1: Plugin
- Finish Tutorial 2: Unit Test Plugin
- Finish Tutorial 3: WebResource
- Finish Tutorial 4: Unit Test WebResource
- A custom workflow get all team members of the current user belong to teams
- A custom workflow send email with email template for all team members of current record
- Add
New Project
04. C# Workflow Project
to solution.- A popup form
Add new Workflow Project
opened - Click button
><
to create/select a Dynamics 365 connection - After connected
PL.DynamicsCrm.DevKit
loaded all entities and bind to dropdownProject Name
- Checkbox
Others
should be checked - Keep the text box
Project Name
empty - Select
9.0.2.4
in theCrm Version
PL.DynamicsCrm.DevKit
get allMicrosoft.CrmSdk.CoreAssemblies
version fromNuGet
- Select
4.5.2
in the.Net version
- Click
OK
-
PL.DynamicsCrm.DevKit
created workflow project name:Paz.LuckeyMonkey.Workflow
- A popup form
- Rebuild solution to restore
NuGet
packages - Add
01. C# Late Bound Class
SystemUser
toEntities
folder ofPaz.LuckeyMonkey.Shared
project. If you don't know how, please check again the Tutorial 1: Plugin - Add
New Item
03. C# Workflow Class
toPaz.LuckeyMonkey.Workflow
project- A popup form opened
- Enter
RetrieveUsers
to texboxClass Name
- Click
OK
-
PL.DynamicsCrm.DevKit
created workflow class:RetrieveUsers
- Edit the
RetrieveUsers.cs
like bellow
public class RetrieveUsers : CodeActivity
{
[Output("UserIds")]
[RequiredArgument]
public OutArgument<string> UserIds { get; set; }
protected override void Execute(CodeActivityContext executionContext)
{
var workflowContext = executionContext.GetExtension<IWorkflowContext>();
var serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
var service = serviceFactory.CreateOrganizationService(workflowContext.UserId);
var tracing = executionContext.GetExtension<ITracingService>();
ExecuteWorkflow(executionContext, workflowContext, serviceFactory, service, tracing);
}
private void ExecuteWorkflow(CodeActivityContext executionContext, IWorkflowContext workflowContext, IOrganizationServiceFactory serviceFactory, IOrganizationService service, ITracingService tracing)
{
Debugger.Trace(tracing, "Begin Execute Workflow: RetrieveUsers");
//YOUR CUSTOM-WORKFLOW-CODE GO HERE
var fetchXml = $@"
<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>
<entity name='systemuser'>
<attribute name='systemuserid'/>
<link-entity name='teammembership' from='systemuserid' to='systemuserid' visible='false' intersect='true'>
<link-entity name='team' from='teamid' to='teamid' alias='aa'>
<link-entity name='teammembership' from='teamid' to='teamid' visible='false' intersect='true'>
<link-entity name='systemuser' from='systemuserid' to='systemuserid' alias='ab'>
<filter type='and'>
<condition attribute='systemuserid' operator='eq-userid'/>
</filter>
</link-entity>
</link-entity>
</link-entity>
</link-entity>
</entity>
</fetch>
";
var users = service.RetrieveAll<SystemUser>(fetchXml);
var userIds = string.Join(";",
users
.Where(u => u.Id != workflowContext.InitiatingUserId)
.Select(u => u.Id).Distinct().ToList());
UserIds.Set(executionContext, userIds);
Debugger.Trace(tracing, "End Execute Workflow: RetrieveUsers");
}
}
NOTED
Remember to use View-FetchXML to copy/paste code
6. Open file PL.DynamicsCrm.DevKit.Cli.json
by Notepad and edit these information in section: workflows.profile = "DEBUG"
* workflows.solution = "LuckeyMonkey"
* workflows.includefiles = "Paz.LuckeyMonkey.*.dll"
7. Run deploy.bat
of project Paz.LuckeyMonkey.Workflow
8.