├── .gitattributes ├── .gitignore ├── Common ├── Common.csproj ├── CrmWorkflowBase.cs ├── Extensions.cs ├── Key.snk ├── Properties │ └── AssemblyInfo.cs ├── WorkflowContext.cs └── packages.config ├── CoreOperations ├── Annotation │ ├── ConvertFile.cs │ ├── DeleteFile.cs │ ├── OperationBaseFile.cs │ └── RenameFile.cs ├── Base │ ├── AddDetailWorkflowBase.cs │ ├── AddDetailWorkflowExtensionBase.cs │ ├── BuildRequestWorkflowBase.cs │ ├── CopyDetailsWorkflowsBase.cs │ ├── CreateChildFromParentWorkflowBase.cs │ ├── GetResolutionWorkflowBase.cs │ └── SetFieldWorkflowBase.cs ├── BuildScript │ ├── Build.ps1 │ ├── ILMerge.exe │ └── Key.snk ├── BulkOperations │ ├── BulkOperationBase.cs │ ├── CascadeStatus.cs │ ├── DistributeAction.cs │ ├── DistributeWorkflow.cs │ └── UpdateRecords.cs ├── Common │ ├── CheckForDuplicates.cs │ ├── Delete.cs │ └── GetRecordId.cs ├── CoreOperations.csproj ├── DateTimeRoutines │ ├── AddBusinessDays.cs │ ├── FormatDateTime.cs │ └── Split.cs ├── Email │ ├── AttachNotesToEmailAndSend.cs │ ├── AttachToRecordFromEmail.cs │ ├── CreateEmailFromTemplate.cs │ ├── SendEmail.cs │ ├── SendEmailToTeam.cs │ └── SendEmailToUnresolvedRecipient.cs ├── Incident │ ├── IncidentClose.cs │ └── IncidentGetResolution.cs ├── Invoice │ ├── InvoiceAddDetail.cs │ ├── InvoiceGetProductsFromOpportunity.cs │ ├── InvoiceLockPricing.cs │ └── InvoiceUnlockPricing.cs ├── Key.snk ├── Lead │ └── LeadQualify.cs ├── NtoN │ ├── AddMemberToMarketingList.cs │ ├── AssociateEntities.cs │ ├── DisassociateEntities.cs │ ├── IsRelationshipExists.cs │ ├── RemoveMemberFromAllMarketingLists.cs │ └── RemoveMemberFromMarketingList.cs ├── Opportunity │ ├── OpportunityAddDetail.cs │ ├── OpportunityGenerateInvoice.cs │ ├── OpportunityGenerateQuote.cs │ ├── OpportunityGenerateSalesOrder.cs │ ├── OpportunityGetResolution.cs │ ├── OpportunityLose.cs │ └── OpportunityWin.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Settings.Designer.cs │ └── Settings.settings ├── Quote │ ├── QuoteAddDetail.cs │ ├── QuoteClose.cs │ ├── QuoteConvertToSalesOrder.cs │ ├── QuoteGetProductsFromOpportunity.cs │ ├── QuoteGetResolution.cs │ ├── QuoteRevise.cs │ └── QuoteWin.cs ├── RequestBuilder │ ├── BuildRequestFromEntity.cs │ ├── SetBooleanField.cs │ ├── SetDateTimeField.cs │ ├── SetDecimalField.cs │ ├── SetFieldToNull.cs │ ├── SetIntField.cs │ ├── SetLookupField.cs │ ├── SetLookupFieldFromQuery.cs │ ├── SetMoneyField.cs │ ├── SetOptionSetField.cs │ └── SetStringField.cs ├── SalesOrder │ ├── SalesOrderAddDetail.cs │ ├── SalesOrderClose.cs │ ├── SalesOrderConvertToInvoice.cs │ ├── SalesOrderFulfill.cs │ ├── SalesOrderGetProductsFromOpportunity.cs │ ├── SalesOrderGetResolution.cs │ ├── SalesOrderLockPricing.cs │ └── SalesOrderUnlockPricing.cs ├── Security │ ├── AddUserToRecordTeam.cs │ ├── AddUserToTeam.cs │ ├── IsUserHasRole.cs │ ├── IsUserMemberOfTeam.cs │ ├── IsUserTeamsHaveRole.cs │ ├── RemoveUserFromRecordTeam.cs │ ├── RemoveUserFromTeam.cs │ ├── ShareRecordWithTeam.cs │ ├── ShareRecordWithUser.cs │ ├── ShareSecuredFieldsBase.cs │ ├── ShareSecuredFieldsWithTeam.cs │ ├── ShareSecuredFieldsWithUser.cs │ ├── UnshareRecordWithTeam.cs │ └── UnshareRecordWithUser.cs ├── StringRoutines │ └── StringJoin.cs ├── System │ ├── CancelOtherInstances.cs │ ├── GeoCodeAddress.cs │ ├── RecalculateAllRollups.cs │ ├── RecalculateRollup.cs │ └── RefreshCurrencyExchangeRates.cs └── packages.config ├── LICENSE ├── MultiselectHelper ├── AddValuesToField.cs ├── FieldContainsAllValues.cs ├── FieldContainsData.cs ├── FieldContainsOneOfValues.cs ├── FieldEqualsTo.cs ├── FieldOperationBase.cs ├── GetFieldLabel.cs ├── Key.snk ├── MultiselectHelper.csproj ├── MultiselectWorkflowBase.cs ├── Properties │ └── AssemblyInfo.cs ├── RemoveValuesFromField.cs ├── SetFieldValue.cs └── packages.config ├── UltimateWorkflowToolkit.sln ├── WebResources ├── Properties │ └── AssemblyInfo.cs ├── WebResources.csproj └── uwt_ │ ├── Settings.html │ ├── Settings.js │ ├── bootstrap │ ├── css │ │ └── bootstrap.min.css │ └── js │ │ └── bootstrap.min.js │ └── jquery3.2.1.min.js └── Workflows └── CaseClose.cs /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | [Xx]64/ 19 | [Xx]86/ 20 | [Bb]uild/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | 85 | # Visual Studio profiler 86 | *.psess 87 | *.vsp 88 | *.vspx 89 | *.sap 90 | 91 | # TFS 2012 Local Workspace 92 | $tf/ 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | *.DotSettings.user 101 | 102 | # JustCode is a .NET coding add-in 103 | .JustCode 104 | 105 | # TeamCity is a build add-in 106 | _TeamCity* 107 | 108 | # DotCover is a Code Coverage Tool 109 | *.dotCover 110 | 111 | # NCrunch 112 | _NCrunch_* 113 | .*crunch*.local.xml 114 | nCrunchTemp_* 115 | 116 | # MightyMoose 117 | *.mm.* 118 | AutoTest.Net/ 119 | 120 | # Web workbench (sass) 121 | .sass-cache/ 122 | 123 | # Installshield output folder 124 | [Ee]xpress/ 125 | 126 | # DocProject is a documentation generator add-in 127 | DocProject/buildhelp/ 128 | DocProject/Help/*.HxT 129 | DocProject/Help/*.HxC 130 | DocProject/Help/*.hhc 131 | DocProject/Help/*.hhk 132 | DocProject/Help/*.hhp 133 | DocProject/Help/Html2 134 | DocProject/Help/html 135 | 136 | # Click-Once directory 137 | publish/ 138 | 139 | # Publish Web Output 140 | *.[Pp]ublish.xml 141 | *.azurePubxml 142 | 143 | # TODO: Un-comment the next line if you do not want to checkin 144 | # your web deploy settings because they may include unencrypted 145 | # passwords 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # NuGet Packages 150 | *.nupkg 151 | # The packages folder can be ignored because of Package Restore 152 | **/packages/* 153 | # except build/, which is used as an MSBuild target. 154 | !**/packages/build/ 155 | # Uncomment if necessary however generally it will be regenerated when needed 156 | #!**/packages/repositories.config 157 | # NuGet v3's project.json files produces more ignoreable files 158 | *.nuget.props 159 | *.nuget.targets 160 | 161 | # Microsoft Azure Build Output 162 | csx/ 163 | *.build.csdef 164 | 165 | # Microsoft Azure Emulator 166 | ecf/ 167 | rcf/ 168 | 169 | # Windows Store app package directory 170 | AppPackages/ 171 | BundleArtifacts/ 172 | 173 | # Visual Studio cache files 174 | # files ending in .cache can be ignored 175 | *.[Cc]ache 176 | # but keep track of directories ending in .cache 177 | !*.[Cc]ache/ 178 | 179 | # Others 180 | ClientBin/ 181 | [Ss]tyle[Cc]op.* 182 | ~$* 183 | *~ 184 | *.dbmdl 185 | *.dbproj.schemaview 186 | *.pfx 187 | *.publishsettings 188 | node_modules/ 189 | orleans.codegen.cs 190 | 191 | # RIA/Silverlight projects 192 | Generated_Code/ 193 | 194 | # Backup & report files from converting an old project file 195 | # to a newer Visual Studio version. Backup files are not needed, 196 | # because we have git ;-) 197 | _UpgradeReport_Files/ 198 | Backup*/ 199 | UpgradeLog*.XML 200 | UpgradeLog*.htm 201 | 202 | # SQL Server files 203 | *.mdf 204 | *.ldf 205 | 206 | # Business Intelligence projects 207 | *.rdl.data 208 | *.bim.layout 209 | *.bim_*.settings 210 | 211 | # Microsoft Fakes 212 | FakesAssemblies/ 213 | 214 | # GhostDoc plugin setting file 215 | *.GhostDoc.xml 216 | 217 | # Node.js Tools for Visual Studio 218 | .ntvs_analysis.dat 219 | 220 | # Visual Studio 6 build log 221 | *.plg 222 | 223 | # Visual Studio 6 workspace options file 224 | *.opt 225 | 226 | # Visual Studio LightSwitch build output 227 | **/*.HTMLClient/GeneratedArtifacts 228 | **/*.DesktopClient/GeneratedArtifacts 229 | **/*.DesktopClient/ModelManifest.xml 230 | **/*.Server/GeneratedArtifacts 231 | **/*.Server/ModelManifest.xml 232 | _Pvt_Extensions 233 | 234 | # LightSwitch generated files 235 | GeneratedArtifacts/ 236 | ModelManifest.xml 237 | 238 | # Paket dependency manager 239 | .paket/paket.exe 240 | 241 | # FAKE - F# Make 242 | .fake/ 243 | /Workflows/CRMDeveloperExtensions.config 244 | /CoreOperations/CRMDeveloperExtensions.config 245 | /WebResources/CRMDeveloperExtensions.config 246 | -------------------------------------------------------------------------------- /Common/Extensions.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | using System.Linq; 3 | using System.Collections.Generic; 4 | 5 | namespace UltimateWorkflowToolkit.Common 6 | { 7 | public static class Extensions 8 | { 9 | public static string UrlEncode(this Dictionary parameters) 10 | { 11 | return string.Join("&", parameters.Select(x => $"{x.Key}={WebUtility.UrlEncode(x.Value.ToString())}")); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Common/Key.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewButenko/UltimateWorkflowToolkit/ccb19d7efc70ddaf54d4ff99371b944f50df131b/Common/Key.snk -------------------------------------------------------------------------------- /Common/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Common")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Common")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("be47db29-fc51-4450-b2c2-98afa33ddfff")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Common/WorkflowContext.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Activities; 3 | using Newtonsoft.Json; 4 | using Microsoft.Xrm.Sdk; 5 | using Microsoft.Xrm.Sdk.Query; 6 | using Microsoft.Xrm.Sdk.Workflow; 7 | 8 | namespace UltimateWorkflowToolkit.Common 9 | { 10 | public class WorkflowContext 11 | { 12 | #region Properties 13 | 14 | public CodeActivityContext ExecutionContext 15 | { 16 | get; 17 | private set; 18 | } 19 | 20 | public IWorkflowContext WorkflowExecutionContext 21 | { 22 | get; 23 | private set; 24 | } 25 | 26 | public IOrganizationService UserService 27 | { 28 | get; 29 | private set; 30 | } 31 | 32 | public IOrganizationService SystemService 33 | { 34 | get; 35 | private set; 36 | } 37 | 38 | public ITracingService TracingService 39 | { 40 | get; 41 | private set; 42 | } 43 | 44 | public UWTSettings Settings 45 | { 46 | get; 47 | private set; 48 | } 49 | 50 | public bool IsSyncMode => WorkflowExecutionContext != null && WorkflowExecutionContext.WorkflowMode == (int) WorkflowExecutionMode.RealTime; 51 | 52 | #endregion Properties 53 | 54 | public WorkflowContext(CodeActivityContext executionContext) 55 | { 56 | ExecutionContext = executionContext; 57 | WorkflowExecutionContext = executionContext.GetExtension(); 58 | 59 | var serviceFactory = executionContext.GetExtension(); 60 | UserService = serviceFactory.CreateOrganizationService(WorkflowExecutionContext.UserId); 61 | SystemService = serviceFactory.CreateOrganizationService(null); 62 | TracingService = executionContext.GetExtension(); 63 | 64 | var settingsQuery = new QueryExpression("uwt_settings") 65 | { 66 | ColumnSet = new ColumnSet("uwt_settingsstring"), 67 | TopCount = 1 68 | }; 69 | 70 | var settingsRecord = SystemService.RetrieveMultiple(settingsQuery).Entities.FirstOrDefault(); 71 | 72 | if (settingsRecord == null || !settingsRecord.Contains("uwt_settingsstring")) return; 73 | try 74 | { 75 | Settings = 76 | JsonConvert.DeserializeObject( 77 | settingsRecord.GetAttributeValue("uwt_settingsstring")); 78 | } 79 | catch 80 | { 81 | } 82 | } 83 | } 84 | 85 | public class UWTSettings 86 | { 87 | public string BingMapsKey { get; set; } 88 | public string CloudConvertKey { get; set; } 89 | public string CurrencylayerKey { get; set; } 90 | public string BaseUrl { get; set; } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /Common/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /CoreOperations/Annotation/ConvertFile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Net; 4 | using System.Text; 5 | using System.Activities; 6 | using Newtonsoft.Json; 7 | using Microsoft.Xrm.Sdk; 8 | using Microsoft.Xrm.Sdk.Workflow; 9 | 10 | namespace UltimateWorkflowToolkit.CoreOperations.Annotation 11 | { 12 | public class ConvertFile: OperationBaseFile 13 | { 14 | #region Inputs/Outputs 15 | 16 | [Input("Resulting File Name")] 17 | [RequiredArgument] 18 | public InArgument ResultingFileName { get; set; } 19 | 20 | [Input("Replace Original File")] 21 | [RequiredArgument] 22 | public InArgument IsReplaceOriginalFile { get; set; } 23 | 24 | #endregion Inputs/Outputs 25 | 26 | protected override void ExecuteOperation(Entity file, EntityReference parentRecord, string currentFileName) 27 | { 28 | var resultingFileName = ResultingFileName.Get(Context.ExecutionContext); 29 | 30 | if (string.IsNullOrEmpty(resultingFileName)) 31 | throw new InvalidPluginExecutionException("Resulting File Name Parameter is empty!"); 32 | 33 | var resultingFileNameParts = resultingFileName.Split('.'); 34 | var currentFileNameParts = currentFileName.Split('.'); 35 | 36 | var baseUrl = "https://api.cloudconvert.com/convert"; 37 | 38 | var request = WebRequest.Create(baseUrl); 39 | 40 | request.Method = "POST"; 41 | request.ContentType = "application/json"; 42 | 43 | var convertFileRequest = new ConvertFileRequest() 44 | { 45 | ApiKey = Context.Settings.CloudConvertKey, 46 | File = file.GetAttributeValue("documentbody"), 47 | OutputFormat = resultingFileNameParts[resultingFileNameParts.Length - 1], 48 | InputMethod = "base64", 49 | FileName = currentFileName, 50 | InputFormat = currentFileNameParts[currentFileNameParts.Length - 1] 51 | }; 52 | 53 | var requestBodyString = JsonConvert.SerializeObject(convertFileRequest); 54 | var requestData = Encoding.Default.GetBytes(requestBodyString); 55 | 56 | using (var stream = request.GetRequestStream()) 57 | { 58 | stream.Write(requestData, 0, requestData.Length); 59 | } 60 | 61 | var inputStream = request.GetResponse().GetResponseStream(); 62 | 63 | var memoStream = new MemoryStream(); 64 | inputStream.CopyTo(memoStream); 65 | inputStream.Close(); 66 | 67 | string newFileContent; 68 | 69 | memoStream.Position = 0; 70 | 71 | using (var msr = new StreamReader(memoStream, Encoding.Default)) 72 | { 73 | newFileContent = msr.ReadToEnd(); 74 | } 75 | 76 | memoStream.Close(); 77 | 78 | var attachment = new Entity("annotation") 79 | { 80 | ["subject"] = file.GetAttributeValue("subject"), 81 | ["filename"] = resultingFileName, 82 | ["documentbody"] = Convert.ToBase64String(Encoding.Default.GetBytes(newFileContent)), 83 | ["isdocument"] = true, 84 | ["objectid"] = parentRecord 85 | }; 86 | 87 | var isReplaceOriginal = IsReplaceOriginalFile.Get(Context.ExecutionContext); 88 | 89 | if (isReplaceOriginal) 90 | { 91 | attachment.Id = file.Id; 92 | Context.UserService.Update(attachment); 93 | } 94 | else 95 | { 96 | Context.UserService.Create(attachment); 97 | } 98 | } 99 | } 100 | 101 | public class ConvertFileRequest 102 | { 103 | [JsonProperty("apikey")] 104 | public string ApiKey { get; set; } 105 | 106 | [JsonProperty("inputformat")] 107 | public string InputFormat { get; set; } 108 | 109 | [JsonProperty("outputformat")] 110 | public string OutputFormat { get; set; } 111 | 112 | [JsonProperty("input")] 113 | public string InputMethod { get; set; } 114 | 115 | [JsonProperty("file")] 116 | public string File { get; set; } 117 | 118 | [JsonProperty("filename")] 119 | public string FileName { get; set; } 120 | 121 | [JsonProperty("wait")] 122 | public bool Wait => true; 123 | 124 | [JsonProperty("download")] 125 | public bool Download => true; 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /CoreOperations/Annotation/DeleteFile.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xrm.Sdk; 2 | 3 | namespace UltimateWorkflowToolkit.CoreOperations.Annotation 4 | { 5 | public class DeleteFile: OperationBaseFile 6 | { 7 | protected override void ExecuteOperation(Entity file, EntityReference parentRecord, string currentFileName) 8 | { 9 | Context.SystemService.Delete("annotation", file.Id); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /CoreOperations/Annotation/OperationBaseFile.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Activities; 3 | using Microsoft.Xrm.Sdk; 4 | using Microsoft.Xrm.Sdk.Query; 5 | using Microsoft.Xrm.Sdk.Workflow; 6 | using UltimateWorkflowToolkit.Common; 7 | 8 | namespace UltimateWorkflowToolkit.CoreOperations.Annotation 9 | { 10 | public abstract class OperationBaseFile : CrmWorkflowBase 11 | { 12 | #region Inputs/Outputs 13 | 14 | [Input("Record Reference")] 15 | [RequiredArgument] 16 | public InArgument Record { get; set; } 17 | 18 | [Input("Current File Name")] 19 | [RequiredArgument] 20 | public InArgument CurrentFileName { get; set; } 21 | 22 | #endregion Inputs/Outputs 23 | 24 | protected abstract void ExecuteOperation(Entity file, EntityReference parentRecord, string currentFileName); 25 | 26 | protected override void ExecuteWorkflowLogic() 27 | { 28 | var record = Record.Get(Context.ExecutionContext); 29 | 30 | if (string.IsNullOrEmpty(record)) 31 | throw new InvalidPluginExecutionException("Record Reference Parameter is empty!"); 32 | 33 | var currentFileName = CurrentFileName.Get(Context.ExecutionContext); 34 | 35 | if (string.IsNullOrEmpty(currentFileName)) 36 | throw new InvalidPluginExecutionException("Current File Name Parameter is empty!"); 37 | 38 | var recordReference = ConvertToEntityReference(record); 39 | 40 | var documentQuery = new QueryByAttribute("annotation") 41 | { 42 | ColumnSet = new ColumnSet("documentbody", "subject"), 43 | TopCount = 1 44 | }; 45 | documentQuery.AddAttributeValue("objectid", recordReference.Id); 46 | documentQuery.AddAttributeValue("isdocument", true); 47 | documentQuery.AddAttributeValue("filename", currentFileName); 48 | 49 | var file = Context.SystemService.RetrieveMultiple(documentQuery).Entities.FirstOrDefault(); 50 | 51 | if (file == null) 52 | { 53 | throw new InvalidPluginExecutionException($"File {currentFileName} is not available for current record"); 54 | } 55 | 56 | ExecuteOperation(file, recordReference, currentFileName); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /CoreOperations/Annotation/RenameFile.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | 5 | namespace UltimateWorkflowToolkit.CoreOperations.Annotation 6 | { 7 | public class RenameFile : OperationBaseFile 8 | { 9 | #region Inputs/Outputs 10 | 11 | [Input("Resulting File Name")] 12 | [RequiredArgument] 13 | public InArgument ResultingFileName { get; set; } 14 | 15 | #endregion Inputs/Outputs 16 | 17 | protected override void ExecuteOperation(Entity file, EntityReference parentRecord, string currentFileName) 18 | { 19 | var resultingFileName = ResultingFileName.Get(Context.ExecutionContext); 20 | 21 | if (string.IsNullOrEmpty(resultingFileName)) 22 | throw new InvalidPluginExecutionException("Resulting File Name Parameter is empty!"); 23 | 24 | file.Attributes.Clear(); 25 | file["filename"] = resultingFileName; 26 | Context.SystemService.Update(file); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /CoreOperations/Base/AddDetailWorkflowBase.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using UltimateWorkflowToolkit.Common; 5 | 6 | namespace UltimateWorkflowToolkit.CoreOperations.Base 7 | { 8 | public abstract class AddDetailWorkflowBase : CrmWorkflowBase 9 | { 10 | #region Inputs 11 | 12 | [Input("Write-in Product")] 13 | public InArgument ProductName { get; set; } 14 | 15 | [Input("Existing Product")] 16 | [ReferenceTarget("product")] 17 | public InArgument ProductId { get; set; } 18 | 19 | [Input("Unit")] 20 | [ReferenceTarget("uom")] 21 | public InArgument UomId { get; set; } 22 | 23 | [Input("Price Overridden")] 24 | public InArgument IsPriceOverridden { get; set; } 25 | 26 | [Input("Price Per Unit")] 27 | public InArgument PricePerUnit { get; set; } 28 | 29 | [Input("Quantity")] 30 | [RequiredArgument] 31 | public InArgument Quantity { get; set; } 32 | 33 | [Input("Manual Discount")] 34 | public InArgument ManualDiscountAmount { get; set; } 35 | 36 | [Input("Tax")] 37 | public InArgument Tax { get; set; } 38 | 39 | [Input("Description")] 40 | public InArgument Description { get; set; } 41 | 42 | #endregion Inputs 43 | 44 | protected abstract string ProductEntityName { get; } 45 | protected abstract string ParentEntityLookupFieldName { get; } 46 | protected abstract EntityReference ParentEntity { get; } 47 | protected abstract void ProcessAdditionalFields(ref Entity record); 48 | 49 | protected override void ExecuteWorkflowLogic() 50 | { 51 | var detailRecord = new Entity(ProductEntityName) 52 | { 53 | [ParentEntityLookupFieldName] = ParentEntity, 54 | ["quantity"] = Quantity.Get(Context.ExecutionContext), 55 | ["description"] = Description.Get(Context.ExecutionContext), 56 | ["manualdiscountamount"] = ManualDiscountAmount.Get(Context.ExecutionContext), 57 | ["tax"] = Tax.Get(Context.ExecutionContext) 58 | }; 59 | 60 | var writeInProduct = ProductName.Get(Context.ExecutionContext); 61 | 62 | if (!string.IsNullOrEmpty(writeInProduct)) 63 | { 64 | detailRecord["productdescription"] = writeInProduct; 65 | detailRecord["isproductoverridden"] = true; 66 | detailRecord["ispriceoverridden"] = true; 67 | detailRecord["priceperunit"] = PricePerUnit.Get(Context.ExecutionContext); 68 | } 69 | else 70 | { 71 | detailRecord["productid"] = ProductId.Get(Context.ExecutionContext); 72 | detailRecord["isproductoverridden"] = false; 73 | detailRecord["uomid"] = UomId.Get(Context.ExecutionContext); 74 | 75 | var ispriceoverridden = IsPriceOverridden.Get(Context.ExecutionContext); 76 | detailRecord["ispriceoverridden"] = ispriceoverridden; 77 | 78 | if (ispriceoverridden) 79 | { 80 | detailRecord["priceperunit"] = PricePerUnit.Get(Context.ExecutionContext); 81 | } 82 | } 83 | 84 | ProcessAdditionalFields(ref detailRecord); 85 | 86 | Context.UserService.Create(detailRecord); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /CoreOperations/Base/AddDetailWorkflowExtensionBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Activities; 3 | using Microsoft.Xrm.Sdk; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | 6 | namespace UltimateWorkflowToolkit.CoreOperations.Base 7 | { 8 | public abstract class AddDetailWorkflowExtensionBase: AddDetailWorkflowBase 9 | { 10 | #region Inputs 11 | 12 | [Input("Salesperson")] 13 | [ReferenceTarget("systemuser")] 14 | public InArgument SalesRepId { get; set; } 15 | 16 | [Input("Ship To - Address(False) or Will Call(True)")] 17 | public InArgument WillCall { get; set; } 18 | 19 | [Input("Ship To Name")] 20 | public InArgument ShipToName { get; set; } 21 | 22 | [Input("Ship To Street 1")] 23 | public InArgument ShipToLine1 { get; set; } 24 | 25 | [Input("Ship To Street 2")] 26 | public InArgument ShipToLine2 { get; set; } 27 | 28 | [Input("Ship To Street 3")] 29 | public InArgument ShipToLine3 { get; set; } 30 | 31 | [Input("Ship To City")] 32 | public InArgument ShipToCity { get; set; } 33 | 34 | [Input("Ship To State/Province")] 35 | public InArgument ShipToStateOrProvince { get; set; } 36 | 37 | [Input("Ship To Zip/Postal Code")] 38 | public InArgument ShipToPostalCode { get; set; } 39 | 40 | [Input("Ship To Country/Region")] 41 | public InArgument ShipToCountry { get; set; } 42 | 43 | [Input("Ship To Phone")] 44 | public InArgument ShipToTelephone { get; set; } 45 | 46 | [Input("Ship To Fax")] 47 | public InArgument ShipToFax { get; set; } 48 | 49 | #endregion Inputs 50 | 51 | protected override void ProcessAdditionalFields(ref Entity record) 52 | { 53 | if (record == null) 54 | throw new ArgumentNullException(nameof(record)); 55 | 56 | record["salesrepid"] = SalesRepId.Get(Context.ExecutionContext); 57 | record["shipto_city"] = ShipToCity.Get(Context.ExecutionContext); 58 | record["shipto_country"] = ShipToCountry.Get(Context.ExecutionContext); 59 | record["shipto_fax"] = ShipToFax.Get(Context.ExecutionContext); 60 | record["shipto_line1"] = ShipToLine1.Get(Context.ExecutionContext); 61 | record["shipto_line2"] = ShipToLine2.Get(Context.ExecutionContext); 62 | record["shipto_line3"] = ShipToLine3.Get(Context.ExecutionContext); 63 | record["shipto_name"] = ShipToName.Get(Context.ExecutionContext); 64 | record["shipto_postalcode"] = ShipToPostalCode.Get(Context.ExecutionContext); 65 | record["shipto_stateorprovince"] = ShipToStateOrProvince.Get(Context.ExecutionContext); 66 | record["shipto_telephone"] = ShipToTelephone.Get(Context.ExecutionContext); 67 | record["willcall"] = WillCall.Get(Context.ExecutionContext); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /CoreOperations/Base/BuildRequestWorkflowBase.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using System.Collections.Generic; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using UltimateWorkflowToolkit.Common; 5 | 6 | namespace UltimateWorkflowToolkit.CoreOperations.Base 7 | { 8 | public abstract class BuildRequestWorkflowBase: CrmWorkflowBase 9 | { 10 | #region Inputs 11 | 12 | [Input("Request")] 13 | [Output("Modified Request")] 14 | public InOutArgument SerializedObject { get; set; } 15 | 16 | #endregion Inputs 17 | 18 | protected abstract void BuildRequest(ref Dictionary request); 19 | 20 | protected override void ExecuteWorkflowLogic() 21 | { 22 | var serializedObject = SerializedObject.Get(Context.ExecutionContext); 23 | var request = DeserializeDictionary(serializedObject); 24 | 25 | BuildRequest(ref request); 26 | 27 | SerializedObject.Set(Context.ExecutionContext, SerializeDictionary(request)); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /CoreOperations/Base/CopyDetailsWorkflowsBase.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Query; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | using Microsoft.Crm.Sdk.Messages; 6 | using UltimateWorkflowToolkit.Common; 7 | 8 | namespace UltimateWorkflowToolkit.CoreOperations.Base 9 | { 10 | public abstract class CopyDetailsWorkflowsBase : CrmWorkflowBase 11 | { 12 | #region Inputs 13 | 14 | [Input("Conditions (leave blank to copy all)")] 15 | public InArgument Conditions { get; set; } 16 | 17 | #endregion Inputs 18 | 19 | protected abstract EntityReference SourceEntityParent { get; } 20 | protected abstract EntityReference TargetEntityParent { get; } 21 | protected abstract string SourceEntity { get; } 22 | protected abstract string SourceEntityLookupFieldName { get; } 23 | protected abstract string TargetEntity { get; } 24 | protected abstract string TargetEntityLookupFieldName { get; } 25 | 26 | protected override void ExecuteWorkflowLogic() 27 | { 28 | var additionalCondition = Conditions.Get(Context.ExecutionContext) ?? string.Empty; 29 | 30 | var sourceEntityFetchXml = $@" 31 | 32 | 33 | 34 | 35 | 36 | {additionalCondition} 37 | 38 | 39 | "; 40 | 41 | var sourceEntityQuery = new FetchExpression(sourceEntityFetchXml); 42 | 43 | var sourceEntities = QueryWithPaging(sourceEntityQuery); 44 | 45 | foreach (var sourceEntity in sourceEntities) 46 | { 47 | var initializeFromRequest = new InitializeFromRequest() 48 | { 49 | EntityMoniker = sourceEntity.ToEntityReference(), 50 | TargetEntityName = TargetEntity, 51 | TargetFieldType = TargetFieldType.ValidForCreate 52 | }; 53 | 54 | var initializeFromResponse = (InitializeFromResponse)Context.UserService.Execute(initializeFromRequest); 55 | 56 | var targetEntity = initializeFromResponse.Entity; 57 | targetEntity[TargetEntityLookupFieldName] = TargetEntityParent; 58 | Context.UserService.Create(targetEntity); 59 | } 60 | } 61 | 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /CoreOperations/Base/CreateChildFromParentWorkflowBase.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Crm.Sdk.Messages; 3 | using Microsoft.Xrm.Sdk; 4 | using Microsoft.Xrm.Sdk.Query; 5 | using Microsoft.Xrm.Sdk.Workflow; 6 | using UltimateWorkflowToolkit.Common; 7 | 8 | namespace UltimateWorkflowToolkit.CoreOperations.Base 9 | { 10 | public abstract class CreateChildFromParentWorkflowBase: CrmWorkflowBase 11 | { 12 | #region Inputs 13 | 14 | [Input("Conditions (leave blank to copy all)")] 15 | public InArgument Conditions { get; set; } 16 | 17 | #endregion Inputs 18 | 19 | protected abstract EntityReference SourceEntity { get; } 20 | protected abstract void SetTargetEntity(EntityReference target); 21 | protected abstract string SourceEntityChild { get; } 22 | protected abstract string SourceEntityLookupFieldName { get; } 23 | protected abstract string TargetEntity { get; } 24 | protected abstract string TargetEntityChild { get; } 25 | protected abstract string TargetEntityLookupFieldName { get; } 26 | 27 | protected override void ExecuteWorkflowLogic() 28 | { 29 | var initializeFromRequest = new InitializeFromRequest() 30 | { 31 | EntityMoniker = SourceEntity, 32 | TargetEntityName = TargetEntity, 33 | TargetFieldType = TargetFieldType.ValidForCreate 34 | }; 35 | 36 | var initializeFromResponse = (InitializeFromResponse)Context.UserService.Execute(initializeFromRequest); 37 | 38 | var targetEntityId = Context.UserService.Create(initializeFromResponse.Entity); 39 | 40 | var target = new EntityReference(TargetEntity, targetEntityId); 41 | 42 | SetTargetEntity(target); 43 | 44 | var additionalCondition = Conditions.Get(Context.ExecutionContext) ?? string.Empty; 45 | 46 | var sourceEntityFetchXml = $@" 47 | 48 | 49 | 50 | 51 | 52 | {additionalCondition} 53 | 54 | 55 | "; 56 | 57 | var sourceEntityQuery = new FetchExpression(sourceEntityFetchXml); 58 | 59 | var sourceEntities = QueryWithPaging(sourceEntityQuery); 60 | 61 | foreach (var sourceEntity in sourceEntities) 62 | { 63 | initializeFromRequest = new InitializeFromRequest() 64 | { 65 | EntityMoniker = sourceEntity.ToEntityReference(), 66 | TargetEntityName = TargetEntityChild, 67 | TargetFieldType = TargetFieldType.ValidForCreate 68 | }; 69 | 70 | initializeFromResponse = (InitializeFromResponse)Context.UserService.Execute(initializeFromRequest); 71 | 72 | var targetEntity = initializeFromResponse.Entity; 73 | targetEntity[TargetEntityLookupFieldName] = target; 74 | Context.UserService.Create(targetEntity); 75 | } 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /CoreOperations/Base/GetResolutionWorkflowBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using Microsoft.Xrm.Sdk; 4 | using Microsoft.Xrm.Sdk.Query; 5 | using UltimateWorkflowToolkit.Common; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations.Base 8 | { 9 | public abstract class GetResolutionWorkflowBase : CrmWorkflowBase 10 | { 11 | #region Abstract Properties 12 | 13 | protected abstract Guid ParentRecordId { get; } 14 | protected abstract string ResolutionEntityName { get; } 15 | protected abstract string ParentRecordLookupFieldName { get; } 16 | protected abstract void SetResolutionEntity(EntityReference resolution); 17 | 18 | #endregion Abstract Properties 19 | 20 | protected override void ExecuteWorkflowLogic() 21 | { 22 | var query = new QueryByAttribute(ResolutionEntityName) 23 | { 24 | ColumnSet = new ColumnSet(false), 25 | PageInfo = new PagingInfo() 26 | { 27 | Count = 1, 28 | PageNumber = 1 29 | } 30 | }; 31 | query.AddAttributeValue(ParentRecordLookupFieldName, ParentRecordId); 32 | query.AddAttributeValue("statecode", 1); 33 | 34 | var resolutionEntity = Context.SystemService.RetrieveMultiple(query).Entities.FirstOrDefault(); 35 | 36 | SetResolutionEntity(resolutionEntity?.ToEntityReference()); 37 | } 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /CoreOperations/Base/SetFieldWorkflowBase.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using System.Collections.Generic; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | 5 | namespace UltimateWorkflowToolkit.CoreOperations.Base 6 | { 7 | public abstract class SetFieldWorkflowBase: BuildRequestWorkflowBase 8 | { 9 | #region Inputs 10 | 11 | [Input("Field Name")] 12 | [RequiredArgument] 13 | public InArgument FieldName { get; set; } 14 | 15 | #endregion Inputs 16 | 17 | protected abstract void AddField(ref Dictionary request, string fieldName); 18 | 19 | protected override void BuildRequest(ref Dictionary request) 20 | { 21 | var fieldName = FieldName.Get(Context.ExecutionContext); 22 | AddField(ref request, fieldName); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /CoreOperations/BuildScript/ILMerge.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewButenko/UltimateWorkflowToolkit/ccb19d7efc70ddaf54d4ff99371b944f50df131b/CoreOperations/BuildScript/ILMerge.exe -------------------------------------------------------------------------------- /CoreOperations/BuildScript/Key.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewButenko/UltimateWorkflowToolkit/ccb19d7efc70ddaf54d4ff99371b944f50df131b/CoreOperations/BuildScript/Key.snk -------------------------------------------------------------------------------- /CoreOperations/BulkOperations/CascadeStatus.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using Microsoft.Crm.Sdk.Messages; 5 | using System.Collections.Generic; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations.BulkOperations 8 | { 9 | public class CascadeStatus : BulkOperationBase 10 | { 11 | #region Input Parameters 12 | 13 | [Input("State Code for Child Record")] 14 | [RequiredArgument] 15 | public InArgument StateCode { get; set; } 16 | 17 | [Input("Status Code for Child Record")] 18 | [RequiredArgument] 19 | public InArgument StatusCode { get; set; } 20 | 21 | #endregion Input Parameters 22 | 23 | protected override void PerformOperation(List childRecords, bool isContinueOnError) 24 | { 25 | foreach (var childRecord in childRecords) 26 | { 27 | try 28 | { 29 | Context.UserService.Execute(new SetStateRequest() 30 | { 31 | EntityMoniker = childRecord.ToEntityReference(), 32 | State = new OptionSetValue(StateCode.Get(Context.ExecutionContext)), 33 | Status = new OptionSetValue(StatusCode.Get(Context.ExecutionContext)) 34 | }); 35 | } 36 | catch 37 | { 38 | if (!isContinueOnError || Context.IsSyncMode) 39 | throw; 40 | } 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /CoreOperations/BulkOperations/DistributeAction.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using System.Collections.Generic; 3 | using Microsoft.Xrm.Sdk; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | 6 | namespace UltimateWorkflowToolkit.CoreOperations.BulkOperations 7 | { 8 | public class DistributeAction : BulkOperationBase 9 | { 10 | #region Inputs 11 | 12 | [Input("Request")] 13 | public InArgument SerializedObject { get; set; } 14 | 15 | [Input("Action Name")] 16 | [RequiredArgument] 17 | public InArgument ActionName { get; set; } 18 | 19 | #endregion Inputs 20 | 21 | protected override void PerformOperation(List childRecords, bool isContinueOnError) 22 | { 23 | var request = DeserializeDictionary(SerializedObject.Get(Context.ExecutionContext)); 24 | 25 | var organizationRequest = new OrganizationRequest(ActionName.Get(Context.ExecutionContext)); 26 | 27 | foreach (var key in request.Keys) 28 | { 29 | organizationRequest[key] = request[key]; 30 | } 31 | 32 | foreach (var childRecord in childRecords) 33 | { 34 | try 35 | { 36 | organizationRequest["Target"] = childRecord.ToEntityReference(); 37 | 38 | Context.UserService.Execute(organizationRequest); 39 | } 40 | catch 41 | { 42 | if (!isContinueOnError || Context.IsSyncMode) 43 | throw; 44 | } 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /CoreOperations/BulkOperations/DistributeWorkflow.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using Microsoft.Crm.Sdk.Messages; 5 | using System.Collections.Generic; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations.BulkOperations 8 | { 9 | public class DistributeWorkflow : BulkOperationBase 10 | { 11 | #region Input Parameters 12 | 13 | [Input("Distributed Workflow")] 14 | [ReferenceTarget("workflow")] 15 | [RequiredArgument] 16 | public InArgument Workflow { get; set; } 17 | 18 | #endregion Input Parameters 19 | 20 | protected override void PerformOperation(List childRecords, bool isContinueOnError) 21 | { 22 | foreach (var childRecord in childRecords) 23 | { 24 | try 25 | { 26 | Context.UserService.Execute(new ExecuteWorkflowRequest() 27 | { 28 | EntityId = childRecord.Id, 29 | WorkflowId = Workflow.Get(Context.ExecutionContext).Id 30 | }); 31 | } 32 | catch 33 | { 34 | if (!isContinueOnError || Context.IsSyncMode) 35 | throw; 36 | } 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /CoreOperations/BulkOperations/UpdateRecords.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using System.Collections.Generic; 5 | 6 | namespace UltimateWorkflowToolkit.CoreOperations.BulkOperations 7 | { 8 | public class UpdateRecords : BulkOperationBase 9 | { 10 | #region Inputs 11 | 12 | [Input("Request")] 13 | public InArgument SerializedObject { get; set; } 14 | 15 | #endregion Inputs 16 | 17 | protected override void PerformOperation(List childRecords, bool isContinueOnError) 18 | { 19 | var request = DeserializeDictionary(SerializedObject.Get(Context.ExecutionContext)); 20 | 21 | foreach (var childRecord in childRecords) 22 | { 23 | var recordToUpdate = new Entity(childRecord.LogicalName, childRecord.Id); 24 | 25 | foreach (var key in request.Keys) 26 | { 27 | recordToUpdate[key] = request[key]; 28 | } 29 | 30 | try 31 | { 32 | Context.UserService.Update(recordToUpdate); 33 | } 34 | catch 35 | { 36 | if (!isContinueOnError || Context.IsSyncMode) 37 | throw; 38 | } 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /CoreOperations/Common/CheckForDuplicates.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Activities; 3 | using System.Collections.Generic; 4 | using Microsoft.Xrm.Sdk.Query; 5 | using Microsoft.Xrm.Sdk.Workflow; 6 | using Microsoft.Xrm.Sdk.Messages; 7 | using Microsoft.Xrm.Sdk.Metadata; 8 | using Microsoft.Crm.Sdk.Messages; 9 | using UltimateWorkflowToolkit.Common; 10 | 11 | namespace UltimateWorkflowToolkit.CoreOperations.Common 12 | { 13 | public class CheckForDuplicates: CrmWorkflowBase 14 | { 15 | #region Input/Output Arguments 16 | 17 | [Input("Record Reference")] 18 | [RequiredArgument] 19 | public InArgument Record { get; set; } 20 | 21 | [Output("Duplicates Exist")] 22 | public OutArgument IsDuplicatesExist { get; set; } 23 | 24 | [Output("Duplicates References")] 25 | public OutArgument DuplicatesReferences { get; set; } 26 | 27 | [Output("Duplicates Table")] 28 | public OutArgument DuplicatesTable { get; set; } 29 | 30 | #endregion Input/Output Arguments 31 | 32 | protected override void ExecuteWorkflowLogic() 33 | { 34 | var target = ConvertToEntityReference(Record.Get(Context.ExecutionContext)); 35 | 36 | var targetRecord = Context.SystemService.Retrieve(target.LogicalName, target.Id, new ColumnSet(true)); 37 | 38 | var retrieveDuplicatesRequest = new RetrieveDuplicatesRequest() 39 | { 40 | BusinessEntity = targetRecord, 41 | MatchingEntityName = target.LogicalName, 42 | PagingInfo = new PagingInfo() 43 | { 44 | Count = 5000, 45 | PageNumber = 1 46 | } 47 | }; 48 | 49 | var retrieveDuplicatesResponse = 50 | (RetrieveDuplicatesResponse) Context.SystemService.Execute(retrieveDuplicatesRequest); 51 | 52 | var dupsExist = retrieveDuplicatesResponse.DuplicateCollection.Entities.Count != 0; 53 | 54 | IsDuplicatesExist.Set(Context.ExecutionContext, dupsExist); 55 | 56 | if (!dupsExist) 57 | return; 58 | 59 | var urlsResult = string.Empty; 60 | var tableResult = ""; 61 | 62 | var entities = new Dictionary(); 63 | 64 | foreach (var dupRecord in retrieveDuplicatesResponse.DuplicateCollection.Entities) 65 | { 66 | var recordUrl = 67 | $"{Context.Settings.BaseUrl}/main.aspx?etn={dupRecord.LogicalName}&pagetype=entityrecord&id={dupRecord.Id}"; 68 | 69 | urlsResult = urlsResult + (urlsResult == string.Empty ? string.Empty : Environment.NewLine) + recordUrl; 70 | 71 | if (!entities.ContainsKey(dupRecord.LogicalName)) 72 | { 73 | var entityMetadata = 74 | ((RetrieveEntityResponse) Context.SystemService.Execute(new RetrieveEntityRequest() 75 | { 76 | EntityFilters = EntityFilters.Entity, 77 | LogicalName = dupRecord.LogicalName, 78 | RetrieveAsIfPublished = true 79 | })).EntityMetadata; 80 | 81 | entities.Add(dupRecord.LogicalName, entityMetadata); 82 | } 83 | 84 | var displayText = 85 | dupRecord.GetAttributeValue(entities[dupRecord.LogicalName].PrimaryNameAttribute) ?? "Not Available"; 86 | 87 | tableResult += $""; 88 | } 89 | 90 | tableResult += "
{displayText}
"; 91 | 92 | DuplicatesReferences.Set(Context.ExecutionContext, urlsResult); 93 | DuplicatesTable.Set(Context.ExecutionContext, tableResult); 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /CoreOperations/Common/Delete.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk.Workflow; 3 | using UltimateWorkflowToolkit.Common; 4 | 5 | namespace UltimateWorkflowToolkit.CoreOperations 6 | { 7 | public class Delete: CrmWorkflowBase 8 | { 9 | #region Input/Output Arguments 10 | 11 | [Input("Record Reference")] 12 | [RequiredArgument] 13 | public InArgument Record { get; set; } 14 | 15 | #endregion Input/Output Arguments 16 | 17 | protected override void ExecuteWorkflowLogic() 18 | { 19 | var target = ConvertToEntityReference(Record.Get(Context.ExecutionContext)); 20 | 21 | Context.SystemService.Delete(target.LogicalName, target.Id); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /CoreOperations/Common/GetRecordId.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk.Workflow; 3 | using UltimateWorkflowToolkit.Common; 4 | 5 | namespace UltimateWorkflowToolkit.CoreOperations.Common 6 | { 7 | public class GetRecordId: CrmWorkflowBase 8 | { 9 | #region Input/Output Arguments 10 | 11 | [Input("Record Reference")] 12 | [RequiredArgument] 13 | public InArgument Record { get; set; } 14 | 15 | [Output("Id")] 16 | public OutArgument RecordId { get; set; } 17 | 18 | [Output("Entity Type Name")] 19 | public OutArgument EntityTypeName { get; set; } 20 | 21 | #endregion Input/Output Arguments 22 | 23 | protected override void ExecuteWorkflowLogic() 24 | { 25 | var target = ConvertToEntityReference(Record.Get(Context.ExecutionContext)); 26 | 27 | RecordId.Set(Context.ExecutionContext, target.Id.ToString()); 28 | EntityTypeName.Set(Context.ExecutionContext, target.LogicalName); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /CoreOperations/DateTimeRoutines/AddBusinessDays.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Activities; 4 | using System.Collections.Generic; 5 | using Microsoft.Xrm.Sdk.Query; 6 | using Microsoft.Xrm.Sdk.Workflow; 7 | using UltimateWorkflowToolkit.Common; 8 | 9 | namespace UltimateWorkflowToolkit.CoreOperations.DateTimeRoutines 10 | { 11 | public class AddBusinessDays : CrmWorkflowBase 12 | { 13 | #region Inputs/Outputs 14 | 15 | [Input("DateTime Value")] 16 | [RequiredArgument] 17 | public InArgument DateTimeValue { get; set; } 18 | 19 | [Input("Days to Add")] 20 | [RequiredArgument] 21 | public InArgument DaystoAdd { get; set; } 22 | 23 | [Input("Weekend Days")] 24 | [RequiredArgument] 25 | [Default("0|6")] 26 | public InArgument WeekendDays { get; set; } 27 | 28 | [Input("Holidays Query (FetchXml)")] 29 | public InArgument HolidaysQuery { get; set; } 30 | 31 | [Output("Resulting DateTime")] 32 | public OutArgument Result { get; set; } 33 | 34 | #endregion Inputs/Outputs 35 | 36 | protected override void ExecuteWorkflowLogic() 37 | { 38 | var result = DateTimeValue.Get(Context.ExecutionContext); 39 | var daysToAdd = DaystoAdd.Get(Context.ExecutionContext); 40 | 41 | var weekendDays = WeekendDays.Get(Context.ExecutionContext).Split('|').Select(t => (DayOfWeek)int.Parse(t)).ToList(); 42 | var holidays = new List(); 43 | 44 | var holidaysQuery = HolidaysQuery.Get(Context.ExecutionContext); 45 | 46 | if (!string.IsNullOrEmpty(holidaysQuery)) 47 | { 48 | holidays = QueryWithPaging(new FetchExpression(holidaysQuery)) 49 | .Where(t => t.Contains("holiday")) 50 | .Select(t => t.GetAttributeValue("holiday").Date) 51 | .ToList(); 52 | } 53 | 54 | while (daysToAdd > 0) 55 | { 56 | result = result.AddDays(1); 57 | 58 | if (weekendDays.Contains(result.DayOfWeek)) 59 | continue; 60 | 61 | if (holidays.Contains(result.Date)) 62 | continue; 63 | 64 | daysToAdd--; 65 | } 66 | 67 | Result.Set(Context.ExecutionContext, result); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /CoreOperations/DateTimeRoutines/FormatDateTime.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Activities; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using UltimateWorkflowToolkit.Common; 5 | 6 | namespace UltimateWorkflowToolkit.CoreOperations.DateTimeRoutines 7 | { 8 | public class FormatDateTime: CrmWorkflowBase 9 | { 10 | #region Inputs/Outputs 11 | 12 | [Input("DateTime Value")] 13 | [RequiredArgument] 14 | public InArgument DateTimeValue { get; set; } 15 | 16 | [Input("Format")] 17 | [RequiredArgument] 18 | public InArgument Format { get; set; } 19 | 20 | [Output("Formatted Value")] 21 | public OutArgument FormattedDateTimeValue { get; set; } 22 | 23 | #endregion Inputs/Outputs 24 | 25 | protected override void ExecuteWorkflowLogic() 26 | { 27 | var formattedValue = 28 | DateTimeValue.Get(Context.ExecutionContext).ToString(Format.Get(Context.ExecutionContext)); 29 | 30 | FormattedDateTimeValue.Set(Context.ExecutionContext, formattedValue); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /CoreOperations/DateTimeRoutines/Split.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Activities; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using UltimateWorkflowToolkit.Common; 5 | 6 | namespace UltimateWorkflowToolkit.CoreOperations.DateTimeRoutines 7 | { 8 | public class Split: CrmWorkflowBase 9 | { 10 | #region Inputs/Outputs 11 | 12 | [Input("DateTime Value")] 13 | [RequiredArgument] 14 | public InArgument DateTimeValue { get; set; } 15 | 16 | [Output("Year")] 17 | public OutArgument Year { get; set; } 18 | 19 | [Output("Month")] 20 | public OutArgument Month { get; set; } 21 | 22 | [Output("Day")] 23 | public OutArgument Day { get; set; } 24 | 25 | [Output("Day of Week")] 26 | public OutArgument DayofWeek { get; set; } 27 | 28 | #endregion Inputs/Outputs 29 | 30 | protected override void ExecuteWorkflowLogic() 31 | { 32 | var dateTimeValue = DateTimeValue.Get(Context.ExecutionContext); 33 | Year.Set(Context.ExecutionContext, dateTimeValue.Year); 34 | Month.Set(Context.ExecutionContext, dateTimeValue.Month); 35 | Day.Set(Context.ExecutionContext, dateTimeValue.Day); 36 | DayofWeek.Set(Context.ExecutionContext, (int)dateTimeValue.DayOfWeek); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /CoreOperations/Email/AttachNotesToEmailAndSend.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Query; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | 6 | namespace UltimateWorkflowToolkit.CoreOperations.Email 7 | { 8 | public class AttachNotesToEmailAndSend : SendEmail 9 | { 10 | #region Inputs/Outputs 11 | 12 | [Input("Record Reference")] 13 | [RequiredArgument] 14 | public InArgument Record { get; set; } 15 | 16 | [Input("Documents Filter")] 17 | public InArgument FilterXml { get; set; } 18 | 19 | [Input("Send Email")] 20 | [RequiredArgument] 21 | [Default("True")] 22 | public InArgument SendAfterOperation { get; set; } 23 | 24 | #endregion Inputs/Outputs 25 | 26 | protected override void ExecuteWorkflowLogic() 27 | { 28 | var sourceRecord = ConvertToEntityReference(Record.Get(Context.ExecutionContext)); 29 | 30 | var documentFilter = FilterXml.Get(Context.ExecutionContext); 31 | 32 | var documentsQuery = $@" 33 | 34 | 35 | 36 | 37 | 38 | 39 | "; 40 | 41 | if (!string.IsNullOrEmpty(documentFilter)) 42 | documentsQuery += documentFilter.Replace('"', '\''); 43 | 44 | documentsQuery += @" 45 | 46 | 47 | "; 48 | 49 | var notes = QueryWithPaging(new FetchExpression(documentsQuery)); 50 | 51 | notes.ForEach(note => 52 | { 53 | var activityattachment = new Entity("activitymimeattachment") 54 | { 55 | ["objectid"] = Email.Get(Context.ExecutionContext), 56 | ["objecttypecode"] = "email", 57 | ["body"] = note["documentbody"], 58 | ["filename"] = note["filename"] 59 | }; 60 | 61 | Context.UserService.Create(activityattachment); 62 | }); 63 | 64 | if (SendAfterOperation.Get(Context.ExecutionContext)) 65 | base.ExecuteWorkflowLogic(); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /CoreOperations/Email/AttachToRecordFromEmail.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Query; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | using UltimateWorkflowToolkit.Common; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations.Email 8 | { 9 | public class AttachToRecordFromEmail : CrmWorkflowBase 10 | { 11 | 12 | #region Inputs 13 | 14 | [Input("Email")] 15 | [RequiredArgument] 16 | [ReferenceTarget("email")] 17 | public InArgument Email { get; set; } 18 | 19 | [Input("Record Reference")] 20 | [RequiredArgument] 21 | public InArgument Record { get; set; } 22 | 23 | 24 | #endregion Inputs 25 | 26 | protected override void ExecuteWorkflowLogic() 27 | { 28 | var attachmentsQuery = new QueryByAttribute("activitymimeattachment") 29 | { 30 | ColumnSet = new ColumnSet("body", "filename") 31 | }; 32 | attachmentsQuery.AddAttributeValue("objectid", Email.Get(Context.ExecutionContext).Id); 33 | 34 | var attachments = QueryWithPaging(attachmentsQuery); 35 | 36 | var record = ConvertToEntityReference(Record.Get(Context.ExecutionContext)); 37 | 38 | attachments.ForEach(attachment => 39 | { 40 | var note = new Entity("annotation") 41 | { 42 | ["documentbody"] = attachment["body"], 43 | ["filename"] = attachment["filename"], 44 | ["isdocument"] = true, 45 | ["objectid"] = record 46 | }; 47 | 48 | Context.UserService.Create(note); 49 | }); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /CoreOperations/Email/CreateEmailFromTemplate.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Query; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | using Microsoft.Crm.Sdk.Messages; 6 | using UltimateWorkflowToolkit.Common; 7 | 8 | namespace UltimateWorkflowToolkit.CoreOperations.Email 9 | { 10 | public class CreateEmailFromTemplate : CrmWorkflowBase 11 | { 12 | 13 | #region Inputs/Outputs 14 | 15 | [Input("Template")] 16 | [RequiredArgument] 17 | [ReferenceTarget("template")] 18 | public InArgument Template { get; set; } 19 | 20 | [Input("Record Reference")] 21 | public InArgument Record { get; set; } 22 | 23 | [Output("Email")] 24 | [ReferenceTarget("email")] 25 | public OutArgument Email { get; set; } 26 | 27 | #endregion Inputs/Outputs 28 | 29 | protected override void ExecuteWorkflowLogic() 30 | { 31 | var templateId = Template.Get(Context.ExecutionContext).Id; 32 | 33 | var template = Context.SystemService.Retrieve("template", templateId, new ColumnSet("templatetypecode")); 34 | 35 | var templateTypeCode = template.GetAttributeValue("templatetypecode"); 36 | 37 | EntityReference targetRecord; 38 | 39 | if (templateTypeCode == "systemuser" && string.IsNullOrEmpty(Record.Get(Context.ExecutionContext))) 40 | { 41 | targetRecord = new EntityReference("systemuser", Context.WorkflowExecutionContext.UserId); 42 | } 43 | else 44 | { 45 | targetRecord = ConvertToEntityReference(Record.Get(Context.ExecutionContext)); 46 | } 47 | 48 | if (templateTypeCode != targetRecord.LogicalName) 49 | throw new InvalidPluginExecutionException("Entities from template and passed as parameter do not fit!"); 50 | 51 | var instantiateTemplateResponse = 52 | (InstantiateTemplateResponse) Context.UserService.Execute(new InstantiateTemplateRequest() 53 | { 54 | ObjectId = targetRecord.Id, 55 | ObjectType = targetRecord.LogicalName, 56 | TemplateId = templateId 57 | }); 58 | 59 | var email = instantiateTemplateResponse.EntityCollection[0]; 60 | email["regardingobjectid"] = targetRecord; 61 | var emailId = Context.UserService.Create(email); 62 | 63 | Email.Set(Context.ExecutionContext, new EntityReference("email", emailId)); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /CoreOperations/Email/SendEmail.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Crm.Sdk.Messages; 3 | using Microsoft.Xrm.Sdk; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | using UltimateWorkflowToolkit.Common; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations.Email 8 | { 9 | public class SendEmail: CrmWorkflowBase 10 | { 11 | #region Inputs/Outputs 12 | 13 | [Input("Email")] 14 | [RequiredArgument] 15 | [ReferenceTarget("email")] 16 | public InArgument Email { get; set; } 17 | 18 | #endregion Inputs/Outputs 19 | 20 | protected override void ExecuteWorkflowLogic() 21 | { 22 | Context.UserService.Execute(new SendEmailRequest() 23 | { 24 | EmailId = Email.Get(Context.ExecutionContext).Id, 25 | IssueSend = true, 26 | TrackingToken = string.Empty 27 | }); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /CoreOperations/Email/SendEmailToTeam.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Query; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | 6 | namespace UltimateWorkflowToolkit.CoreOperations.Email 7 | { 8 | public class SendEmailToTeam : SendEmail 9 | { 10 | #region Inputs/Outputs 11 | 12 | [Input("Team")] 13 | [RequiredArgument] 14 | [ReferenceTarget("team")] 15 | public InArgument Team { get; set; } 16 | 17 | [Input("Send Email")] 18 | [RequiredArgument] 19 | [Default("True")] 20 | public InArgument SendAfterOperation { get; set; } 21 | 22 | #endregion Inputs/Outputs 23 | 24 | protected override void ExecuteWorkflowLogic() 25 | { 26 | var emailId = Email.Get(Context.ExecutionContext).Id; 27 | 28 | var email = Context.UserService.Retrieve("email", emailId, new ColumnSet("to")); 29 | var to = email.Contains("to") ? email.GetAttributeValue("to") : new EntityCollection(); 30 | 31 | var userQuery = new QueryExpression("systemuser") 32 | { 33 | ColumnSet = new ColumnSet(false) 34 | }; 35 | var teamLink = userQuery.AddLink("teammembership", "systemuserid", "systemuserid"); 36 | teamLink.LinkCriteria.AddCondition("teamid", ConditionOperator.Equal, Team.Get(Context.ExecutionContext).Id); 37 | 38 | var users = QueryWithPaging(userQuery); 39 | 40 | users.ForEach(u => 41 | { 42 | to.Entities.Add(new Entity("activityparty") 43 | { 44 | ["partyid"] = u.ToEntityReference() 45 | }); 46 | }); 47 | 48 | email["to"] = to; 49 | Context.UserService.Update(email); 50 | 51 | if (SendAfterOperation.Get(Context.ExecutionContext)) 52 | base.ExecuteWorkflowLogic(); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /CoreOperations/Email/SendEmailToUnresolvedRecipient.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Query; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | 6 | namespace UltimateWorkflowToolkit.CoreOperations.Email 7 | { 8 | public class SendEmailToUnresolvedRecipient : SendEmail 9 | { 10 | #region Inputs/Outputs 11 | 12 | [Input("Recipient Email")] 13 | [RequiredArgument] 14 | public InArgument RecipientEmail { get; set; } 15 | 16 | [Input("Send Email")] 17 | [RequiredArgument] 18 | [Default("True")] 19 | public InArgument SendAfterOperation { get; set; } 20 | 21 | #endregion Inputs/Outputs 22 | 23 | protected override void ExecuteWorkflowLogic() 24 | { 25 | var emailId = Email.Get(Context.ExecutionContext).Id; 26 | 27 | var email = Context.UserService.Retrieve("email", emailId, new ColumnSet("to")); 28 | 29 | var to = email.Contains("to") ? email.GetAttributeValue("to") : new EntityCollection(); 30 | var newRecipient = new Entity("activityparty") 31 | { 32 | ["addressused"] = RecipientEmail.Get(Context.ExecutionContext) 33 | }; 34 | to.Entities.Add(newRecipient); 35 | 36 | email["to"] = to; 37 | 38 | Context.UserService.Update(email); 39 | 40 | if (SendAfterOperation.Get(Context.ExecutionContext)) 41 | base.ExecuteWorkflowLogic(); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /CoreOperations/Incident/IncidentClose.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using Microsoft.Crm.Sdk.Messages; 5 | using UltimateWorkflowToolkit.Common; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations 8 | { 9 | public class CaseClose : CrmWorkflowBase 10 | { 11 | #region Input/Output Parameters 12 | 13 | [Input("Case")] 14 | [ReferenceTarget("incident")] 15 | [RequiredArgument] 16 | public InArgument Incident { get; set; } 17 | 18 | [Input("Case Status")] 19 | [AttributeTarget("incident", "statuscode")] 20 | [RequiredArgument] 21 | public InArgument IncidentStatus { get; set; } 22 | 23 | [Input("Case Close: Subject")] 24 | public InArgument Subject { get; set; } 25 | 26 | [Input("Case Close: Description")] 27 | public InArgument Description { get; set; } 28 | 29 | [Input("Case Close: Time Spent")] 30 | public InArgument TimeSpent { get; set; } 31 | 32 | #endregion Input/Output Parameters 33 | 34 | protected override void ExecuteWorkflowLogic() 35 | { 36 | var incidentCloseRequest = new CloseIncidentRequest() 37 | { 38 | Status = IncidentStatus.Get(Context.ExecutionContext), 39 | IncidentResolution = new Entity("incidentresolution") 40 | { 41 | ["subject"] = Subject.Get(Context.ExecutionContext), 42 | ["incidentid"] = Incident.Get(Context.ExecutionContext), 43 | ["description"] = Description.Get(Context.ExecutionContext), 44 | ["timespent"] = TimeSpent.Get(Context.ExecutionContext) 45 | } 46 | }; 47 | 48 | Context.UserService.Execute(incidentCloseRequest); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /CoreOperations/Incident/IncidentGetResolution.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Activities; 3 | using Microsoft.Xrm.Sdk; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | using UltimateWorkflowToolkit.CoreOperations.Base; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations 8 | { 9 | public class IncidentGetResolution: GetResolutionWorkflowBase 10 | { 11 | #region Input/Output Parameters 12 | 13 | [Input("Case")] 14 | [ReferenceTarget("incident")] 15 | [RequiredArgument] 16 | public InArgument Case { get; set; } 17 | 18 | [Output("Case Resolution")] 19 | [ReferenceTarget("incidentresolution")] 20 | public OutArgument CaseResolution { get; set; } 21 | 22 | #endregion Input/Output Parameters 23 | 24 | protected override Guid ParentRecordId => Case.Get(Context.ExecutionContext).Id; 25 | 26 | protected override string ResolutionEntityName => "incidentresolution"; 27 | 28 | protected override string ParentRecordLookupFieldName => "incidentid"; 29 | 30 | protected override void SetResolutionEntity(EntityReference resolution) 31 | { 32 | CaseResolution.Set(Context.ExecutionContext, resolution); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /CoreOperations/Invoice/InvoiceAddDetail.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Activities; 3 | using Microsoft.Xrm.Sdk; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | using UltimateWorkflowToolkit.CoreOperations.Base; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations.Invoice 8 | { 9 | public class InvoiceAddDetail : AddDetailWorkflowExtensionBase 10 | { 11 | #region Inputs 12 | 13 | [Input("Invoice")] 14 | [ReferenceTarget("invoice")] 15 | [RequiredArgument] 16 | public InArgument Invoice { get; set; } 17 | 18 | [Input("Delievered On")] 19 | public InArgument ActualDeliveryOn { get; set; } 20 | 21 | [Input("Copied")] 22 | [Default("False")] 23 | public InArgument IsCopied { get; set; } 24 | 25 | [Input("Freight Terms")] 26 | [AttributeTarget("invoicedetail", "shipto_freighttermscode")] 27 | public InArgument ShipToFreightTerms { get; set; } 28 | 29 | [Input("Quantity Back Ordered")] 30 | public InArgument QuantityBackOrdered { get; set; } 31 | 32 | [Input("Quantity Canceled")] 33 | public InArgument QuantityCancelled { get; set; } 34 | 35 | [Input("Quantity Shipped")] 36 | public InArgument QuantityShipped { get; set; } 37 | 38 | [Input("Shipment Tracking Number")] 39 | public InArgument ShippingTrackingNumber { get; set; } 40 | 41 | #endregion Inputs 42 | 43 | protected override string ProductEntityName => "invoicedetail"; 44 | protected override string ParentEntityLookupFieldName => "invoiceid"; 45 | protected override EntityReference ParentEntity => Invoice.Get(Context.ExecutionContext); 46 | 47 | protected override void ProcessAdditionalFields(ref Entity record) 48 | { 49 | record["actualdeliveryon"] = ActualDeliveryOn.Get(Context.ExecutionContext); 50 | record["iscopied"] = IsCopied.Get(Context.ExecutionContext); 51 | record["shipto_freighttermscode"] = ShipToFreightTerms.Get(Context.ExecutionContext); 52 | record["quantitybackordered"] = QuantityBackOrdered.Get(Context.ExecutionContext); 53 | record["quantitycancelled"] = QuantityCancelled.Get(Context.ExecutionContext); 54 | record["quantityshipped"] = QuantityShipped.Get(Context.ExecutionContext); 55 | record["shippingtrackingnumber"] = ShippingTrackingNumber.Get(Context.ExecutionContext); 56 | 57 | base.ProcessAdditionalFields(ref record); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /CoreOperations/Invoice/InvoiceGetProductsFromOpportunity.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using UltimateWorkflowToolkit.CoreOperations.Base; 5 | 6 | namespace UltimateWorkflowToolkit.CoreOperations 7 | { 8 | public class InvoiceGetProductsFromOpportunity : CopyDetailsWorkflowsBase 9 | { 10 | 11 | #region Input/Output Parameters 12 | 13 | [Input("Invoice")] 14 | [ReferenceTarget("invoice")] 15 | [RequiredArgument] 16 | public InArgument Invoice { get; set; } 17 | 18 | [Input("Opportunity")] 19 | [ReferenceTarget("opportunity")] 20 | [RequiredArgument] 21 | public InArgument Opportunity { get; set; } 22 | 23 | #endregion Input/Output Parameters 24 | 25 | protected override EntityReference SourceEntityParent => Opportunity.Get(Context.ExecutionContext); 26 | 27 | protected override EntityReference TargetEntityParent => Invoice.Get(Context.ExecutionContext); 28 | 29 | protected override string SourceEntity => "opportunityproduct"; 30 | protected override string SourceEntityLookupFieldName => "opportunityid"; 31 | protected override string TargetEntity => "invoicedetail"; 32 | protected override string TargetEntityLookupFieldName => "invoiceid"; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /CoreOperations/Invoice/InvoiceLockPricing.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using Microsoft.Crm.Sdk.Messages; 5 | using UltimateWorkflowToolkit.Common; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations 8 | { 9 | public class InvoiceLockPricing : CrmWorkflowBase 10 | { 11 | #region Input/Output Parameters 12 | 13 | [Input("Invoice")] 14 | [ReferenceTarget("invoice")] 15 | [RequiredArgument] 16 | public InArgument Invoice { get; set; } 17 | 18 | #endregion Input/Output Parameters 19 | 20 | protected override void ExecuteWorkflowLogic() 21 | { 22 | var lockInvoicePricingRequest = new LockInvoicePricingRequest() 23 | { 24 | InvoiceId = Invoice.Get(Context.ExecutionContext).Id 25 | }; 26 | 27 | Context.UserService.Execute(lockInvoicePricingRequest); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /CoreOperations/Invoice/InvoiceUnlockPricing.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using Microsoft.Crm.Sdk.Messages; 5 | using UltimateWorkflowToolkit.Common; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations 8 | { 9 | public class InvoiceUnlockPricing : CrmWorkflowBase 10 | { 11 | #region Input/Output Parameters 12 | 13 | [Input("Invoice")] 14 | [ReferenceTarget("invoice")] 15 | [RequiredArgument] 16 | public InArgument Invoice { get; set; } 17 | 18 | #endregion Input/Output Parameters 19 | 20 | protected override void ExecuteWorkflowLogic() 21 | { 22 | var unlockInvoicePricingRequest = new UnlockInvoicePricingRequest() 23 | { 24 | InvoiceId = Invoice.Get(Context.ExecutionContext).Id 25 | }; 26 | 27 | Context.UserService.Execute(unlockInvoicePricingRequest); 28 | } 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /CoreOperations/Key.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewButenko/UltimateWorkflowToolkit/ccb19d7efc70ddaf54d4ff99371b944f50df131b/CoreOperations/Key.snk -------------------------------------------------------------------------------- /CoreOperations/Lead/LeadQualify.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xrm.Sdk; 2 | using Microsoft.Xrm.Sdk.Workflow; 3 | using System.Activities; 4 | using Microsoft.Crm.Sdk.Messages; 5 | using UltimateWorkflowToolkit.Common; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations 8 | { 9 | public class LeadQualify : CrmWorkflowBase 10 | { 11 | #region Input/Output Parameters 12 | 13 | [Input("Lead")] 14 | [ReferenceTarget("lead")] 15 | [RequiredArgument] 16 | public InArgument Lead { get; set; } 17 | 18 | [Input("Lead Status")] 19 | [AttributeTarget("lead", "statuscode")] 20 | [RequiredArgument] 21 | public InArgument LeadStatus { get; set; } 22 | 23 | [Input("Create Account")] 24 | [RequiredArgument] 25 | public InArgument IsCreateAccont { get; set; } 26 | 27 | [Output("Created Account")] 28 | [ReferenceTarget("account")] 29 | public OutArgument Account { get; set; } 30 | 31 | [Input("Create Contact")] 32 | [RequiredArgument] 33 | public InArgument IsCreateContact { get; set; } 34 | 35 | [Output("Created Contact")] 36 | [ReferenceTarget("contact")] 37 | public OutArgument Contact { get; set; } 38 | 39 | [Input("Create Opportunity")] 40 | [RequiredArgument] 41 | public InArgument IsCreateOpportunity { get; set; } 42 | 43 | [Output("Created Opportunity")] 44 | [ReferenceTarget("opportunity")] 45 | public OutArgument Opportunity { get; set; } 46 | 47 | [Input("Currency")] 48 | [ReferenceTarget("transactioncurrency")] 49 | public InArgument Currency { get; set; } 50 | 51 | [Input("Opportunity Customer(Account)")] 52 | [ReferenceTarget("account")] 53 | public InArgument OpportunityCustomerAccount { get; set; } 54 | 55 | [Input("Opportunity Customer(Contact)")] 56 | [ReferenceTarget("contact")] 57 | public InArgument OpportunityCustomerContact { get; set; } 58 | 59 | #endregion 60 | 61 | protected override void ExecuteWorkflowLogic() 62 | { 63 | var qualifyLeadRequest = new QualifyLeadRequest() 64 | { 65 | CreateAccount = IsCreateAccont.Get(Context.ExecutionContext), 66 | CreateContact = IsCreateContact.Get(Context.ExecutionContext), 67 | CreateOpportunity = IsCreateOpportunity.Get(Context.ExecutionContext), 68 | LeadId = Lead.Get(Context.ExecutionContext), 69 | Status = LeadStatus.Get(Context.ExecutionContext), 70 | OpportunityCurrencyId = Currency.Get(Context.ExecutionContext) 71 | }; 72 | 73 | if (OpportunityCustomerAccount.Get(Context.ExecutionContext) != null) 74 | { 75 | qualifyLeadRequest.OpportunityCustomerId = OpportunityCustomerAccount.Get(Context.ExecutionContext); 76 | } 77 | else if (OpportunityCustomerContact.Get(Context.ExecutionContext) != null) 78 | { 79 | qualifyLeadRequest.OpportunityCustomerId = OpportunityCustomerContact.Get(Context.ExecutionContext); 80 | } 81 | 82 | var qualifyLeadResponse = (QualifyLeadResponse)Context.UserService.Execute(qualifyLeadRequest); 83 | 84 | foreach (var createdEntity in qualifyLeadResponse.CreatedEntities) 85 | { 86 | switch (createdEntity.LogicalName) 87 | { 88 | case "account": 89 | Account.Set(Context.ExecutionContext, createdEntity); 90 | break; 91 | case "contact": 92 | Contact.Set(Context.ExecutionContext, createdEntity); 93 | break; 94 | case "opportunity": 95 | Opportunity.Set(Context.ExecutionContext, createdEntity); 96 | break; 97 | } 98 | } 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /CoreOperations/NtoN/AddMemberToMarketingList.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using Microsoft.Crm.Sdk.Messages; 5 | using UltimateWorkflowToolkit.Common; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations.NtoN 8 | { 9 | public class AddMemberToMarketingList : CrmWorkflowBase 10 | { 11 | #region Input/Output Parameters 12 | 13 | [Input("Record Reference")] 14 | [RequiredArgument] 15 | public InArgument Record { get; set; } 16 | 17 | [Input("Marketing List")] 18 | [RequiredArgument] 19 | [ReferenceTarget("list")] 20 | public InArgument List { get; set; } 21 | 22 | #endregion Input/Output Parameters 23 | 24 | protected override void ExecuteWorkflowLogic() 25 | { 26 | var record = ConvertToEntityReference(Record.Get(Context.ExecutionContext)); 27 | 28 | Context.UserService.Execute(new AddMemberListRequest() 29 | { 30 | EntityId = record.Id, 31 | ListId = List.Get(Context.ExecutionContext).Id 32 | }); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /CoreOperations/NtoN/AssociateEntities.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk.Workflow; 3 | using Microsoft.Crm.Sdk.Messages; 4 | using UltimateWorkflowToolkit.Common; 5 | 6 | namespace UltimateWorkflowToolkit.CoreOperations.NtoN 7 | { 8 | public class AssociateEntities : CrmWorkflowBase 9 | { 10 | #region Input/Output Parameters 11 | 12 | [Input("Record 1 Reference")] 13 | [RequiredArgument] 14 | public InArgument Record1Id { get; set; } 15 | 16 | [Input("Record 2 Reference")] 17 | [RequiredArgument] 18 | public InArgument Record2Id { get; set; } 19 | 20 | [Input("Relationship Name")] 21 | [RequiredArgument] 22 | public InArgument RelationshipName { get; set; } 23 | 24 | #endregion Input/Output Parameters 25 | 26 | protected override void ExecuteWorkflowLogic() 27 | { 28 | var record1 = ConvertToEntityReference(Record1Id.Get(Context.ExecutionContext)); 29 | var record2 = ConvertToEntityReference(Record2Id.Get(Context.ExecutionContext)); 30 | 31 | Context.UserService.Execute(new AssociateEntitiesRequest() 32 | { 33 | Moniker1 = record1, 34 | Moniker2 = record2, 35 | RelationshipName = RelationshipName.Get(Context.ExecutionContext) 36 | }); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /CoreOperations/NtoN/DisassociateEntities.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk.Workflow; 3 | using Microsoft.Crm.Sdk.Messages; 4 | using UltimateWorkflowToolkit.Common; 5 | 6 | namespace UltimateWorkflowToolkit.CoreOperations.NtoN 7 | { 8 | public class DisassociateEntities : CrmWorkflowBase 9 | { 10 | #region Input/Output Parameters 11 | 12 | [Input("Record 1 Reference")] 13 | [RequiredArgument] 14 | public InArgument Record1Id { get; set; } 15 | 16 | [Input("Record 2 Reference")] 17 | [RequiredArgument] 18 | public InArgument Record2Id { get; set; } 19 | 20 | [Input("Relationship Name")] 21 | [RequiredArgument] 22 | public InArgument RelationshipName { get; set; } 23 | 24 | #endregion Input/Output Parameters 25 | 26 | protected override void ExecuteWorkflowLogic() 27 | { 28 | var record1 = ConvertToEntityReference(Record1Id.Get(Context.ExecutionContext)); 29 | var record2 = ConvertToEntityReference(Record2Id.Get(Context.ExecutionContext)); 30 | 31 | Context.UserService.Execute(new DisassociateEntitiesRequest() 32 | { 33 | Moniker1 = record1, 34 | Moniker2 = record2, 35 | RelationshipName = RelationshipName.Get(Context.ExecutionContext) 36 | }); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /CoreOperations/NtoN/IsRelationshipExists.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using Microsoft.Xrm.Sdk.Messages; 5 | using Microsoft.Xrm.Sdk.Query; 6 | using UltimateWorkflowToolkit.Common; 7 | 8 | namespace UltimateWorkflowToolkit.CoreOperations.NtoN 9 | { 10 | public class IsRelationshipExists : CrmWorkflowBase 11 | { 12 | #region Input/Output Parameters 13 | 14 | [Input("Record 1 Reference")] 15 | [RequiredArgument] 16 | public InArgument Record1Id { get; set; } 17 | 18 | [Input("Record 2 Reference")] 19 | [RequiredArgument] 20 | public InArgument Record2Id { get; set; } 21 | 22 | [Input("Relationship Name")] 23 | [RequiredArgument] 24 | public InArgument RelationshipName { get; set; } 25 | 26 | [Output("Is Relationship Exists")] 27 | public OutArgument RelationshipExists { get; set; } 28 | 29 | #endregion Input/Output Parameters 30 | 31 | protected override void ExecuteWorkflowLogic() 32 | { 33 | var record1 = ConvertToEntityReference(Record1Id.Get(Context.ExecutionContext)); 34 | var record2 = ConvertToEntityReference(Record2Id.Get(Context.ExecutionContext)); 35 | 36 | var record2Query = new QueryByAttribute(record2.LogicalName) 37 | { 38 | ColumnSet = new ColumnSet(false) 39 | }; 40 | record2Query.AddAttributeValue($"{record2.LogicalName}id", record2.Id); 41 | 42 | var relationship = new Relationship(RelationshipName.Get(Context.ExecutionContext)); 43 | 44 | var retrieveRequest = new RetrieveRequest() 45 | { 46 | ColumnSet = new ColumnSet(false), 47 | Target = record1, 48 | RelatedEntitiesQuery = new RelationshipQueryCollection 49 | { 50 | {relationship, record2Query} 51 | } 52 | }; 53 | 54 | var retrieveResponse = (RetrieveResponse) Context.SystemService.Execute(retrieveRequest); 55 | 56 | var isRelationshipExists = retrieveResponse.Entity.RelatedEntities[relationship].Entities.Count != 0; 57 | 58 | RelationshipExists.Set(Context.ExecutionContext, isRelationshipExists); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /CoreOperations/NtoN/RemoveMemberFromAllMarketingLists.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk.Workflow; 3 | using Microsoft.Crm.Sdk.Messages; 4 | using Microsoft.Xrm.Sdk.Query; 5 | using UltimateWorkflowToolkit.Common; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations.NtoN 8 | { 9 | public class RemoveMemberFromAllMarketingLists : CrmWorkflowBase 10 | { 11 | #region Input/Output Parameters 12 | 13 | [Input("Record Reference")] 14 | [RequiredArgument] 15 | public InArgument Record { get; set; } 16 | 17 | #endregion Input/Output Parameters 18 | 19 | protected override void ExecuteWorkflowLogic() 20 | { 21 | var record = ConvertToEntityReference(Record.Get(Context.ExecutionContext)); 22 | 23 | var listsQuery = new QueryExpression("list") 24 | { 25 | ColumnSet = new ColumnSet(false) 26 | }; 27 | var listMemberLink = listsQuery.AddLink("listmember", "listid", "listid"); 28 | listMemberLink.LinkCriteria.AddCondition("entityid", ConditionOperator.Equal, record.Id); 29 | 30 | var allLists = QueryWithPaging(listsQuery); 31 | 32 | allLists.ForEach(l => Context.UserService.Execute(new RemoveMemberListRequest() 33 | { 34 | EntityId = record.Id, 35 | ListId = l.Id 36 | })); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /CoreOperations/NtoN/RemoveMemberFromMarketingList.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using Microsoft.Crm.Sdk.Messages; 5 | using UltimateWorkflowToolkit.Common; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations.NtoN 8 | { 9 | public class RemoveMemberFromMarketingList : CrmWorkflowBase 10 | { 11 | #region Input/Output Parameters 12 | 13 | [Input("Record Reference")] 14 | [RequiredArgument] 15 | public InArgument Record { get; set; } 16 | 17 | [Input("Marketing List")] 18 | [RequiredArgument] 19 | [ReferenceTarget("list")] 20 | public InArgument List { get; set; } 21 | 22 | #endregion Input/Output Parameters 23 | 24 | protected override void ExecuteWorkflowLogic() 25 | { 26 | var record = ConvertToEntityReference(Record.Get(Context.ExecutionContext)); 27 | 28 | Context.UserService.Execute(new RemoveMemberListRequest() 29 | { 30 | EntityId = record.Id, 31 | ListId = List.Get(Context.ExecutionContext).Id 32 | }); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /CoreOperations/Opportunity/OpportunityAddDetail.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using UltimateWorkflowToolkit.CoreOperations.Base; 5 | 6 | namespace UltimateWorkflowToolkit.CoreOperations.Opportunity 7 | { 8 | public class OpportunityAddDetail : AddDetailWorkflowBase 9 | { 10 | #region Input Arguments 11 | 12 | [Input("Opportunity")] 13 | [ReferenceTarget("opportunity")] 14 | [RequiredArgument] 15 | public InArgument Opportunity { get; set; } 16 | 17 | #endregion Input Arguments 18 | 19 | protected override string ProductEntityName => "opportunityproduct"; 20 | protected override string ParentEntityLookupFieldName => "opportunityid"; 21 | protected override EntityReference ParentEntity => Opportunity.Get(Context.ExecutionContext); 22 | 23 | protected override void ProcessAdditionalFields(ref Entity record) 24 | { 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /CoreOperations/Opportunity/OpportunityGenerateInvoice.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using UltimateWorkflowToolkit.CoreOperations.Base; 5 | 6 | namespace UltimateWorkflowToolkit.CoreOperations 7 | { 8 | public class OpportunityGenerateInvoice : CreateChildFromParentWorkflowBase 9 | { 10 | #region Input/Output Parameters 11 | 12 | [Input("Opportunity")] 13 | [ReferenceTarget("opportunity")] 14 | [RequiredArgument] 15 | public InArgument Opportunity { get; set; } 16 | 17 | [Output("Invoice")] 18 | [ReferenceTarget("invoice")] 19 | public OutArgument Invoice { get; set; } 20 | 21 | #endregion Input/Output Parameters 22 | 23 | protected override EntityReference SourceEntity => Opportunity.Get(Context.ExecutionContext); 24 | 25 | protected override void SetTargetEntity(EntityReference target) 26 | { 27 | Invoice.Set(Context.ExecutionContext, target); 28 | } 29 | 30 | protected override string SourceEntityChild => "opportunityproduct"; 31 | protected override string SourceEntityLookupFieldName => "opportunityid"; 32 | protected override string TargetEntity => "invoice"; 33 | protected override string TargetEntityChild => "invoicedetail"; 34 | protected override string TargetEntityLookupFieldName => "invoiceid"; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /CoreOperations/Opportunity/OpportunityGenerateQuote.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using UltimateWorkflowToolkit.CoreOperations.Base; 5 | 6 | namespace UltimateWorkflowToolkit.CoreOperations 7 | { 8 | public class OpportunityGenerateQuote : CreateChildFromParentWorkflowBase 9 | { 10 | #region Input/Output Parameters 11 | 12 | [Input("Opportunity")] 13 | [ReferenceTarget("opportunity")] 14 | [RequiredArgument] 15 | public InArgument Opportunity { get; set; } 16 | 17 | [Output("Quote")] 18 | [ReferenceTarget("quote")] 19 | public OutArgument Quote { get; set; } 20 | 21 | #endregion Input/Output Parameters 22 | 23 | protected override EntityReference SourceEntity => Opportunity.Get(Context.ExecutionContext); 24 | 25 | protected override void SetTargetEntity(EntityReference target) 26 | { 27 | Quote.Set(Context.ExecutionContext, target); 28 | } 29 | 30 | protected override string SourceEntityChild => "opportunityproduct"; 31 | protected override string SourceEntityLookupFieldName => "opportunityid"; 32 | protected override string TargetEntity => "quote"; 33 | protected override string TargetEntityChild => "quotedetail"; 34 | protected override string TargetEntityLookupFieldName => "quoteid"; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /CoreOperations/Opportunity/OpportunityGenerateSalesOrder.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using UltimateWorkflowToolkit.CoreOperations.Base; 5 | 6 | namespace UltimateWorkflowToolkit.CoreOperations 7 | { 8 | public class OpportunityGenerateSalesOrder : CreateChildFromParentWorkflowBase 9 | { 10 | #region Input/Output Parameters 11 | 12 | [Input("Opportunity")] 13 | [ReferenceTarget("opportunity")] 14 | [RequiredArgument] 15 | public InArgument Opportunity { get; set; } 16 | 17 | [Output("Sales Order")] 18 | [ReferenceTarget("salesorder")] 19 | public OutArgument SalesOrder { get; set; } 20 | 21 | #endregion Input/Output Parameters 22 | 23 | protected override EntityReference SourceEntity => Opportunity.Get(Context.ExecutionContext); 24 | 25 | protected override void SetTargetEntity(EntityReference target) 26 | { 27 | SalesOrder.Set(Context.ExecutionContext, target); 28 | } 29 | 30 | protected override string SourceEntityChild => "opportunityproduct"; 31 | protected override string SourceEntityLookupFieldName => "opportunityid"; 32 | protected override string TargetEntity => "salesorder"; 33 | protected override string TargetEntityChild => "salesorderdetail"; 34 | protected override string TargetEntityLookupFieldName => "salesorderid"; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /CoreOperations/Opportunity/OpportunityGetResolution.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Activities; 3 | using Microsoft.Xrm.Sdk; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | using UltimateWorkflowToolkit.CoreOperations.Base; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations 8 | { 9 | public class OpportunityGetResolution: GetResolutionWorkflowBase 10 | { 11 | #region Input/Output Parameters 12 | 13 | [Input("Opportunity")] 14 | [ReferenceTarget("opportunity")] 15 | [RequiredArgument] 16 | public InArgument Opportunity { get; set; } 17 | 18 | [Output("Opportunity Close")] 19 | [ReferenceTarget("opportunityclose")] 20 | public OutArgument OpportunityClose { get; set; } 21 | 22 | #endregion Input/Output Parameters 23 | 24 | protected override Guid ParentRecordId => Opportunity.Get(Context.ExecutionContext).Id; 25 | 26 | protected override string ResolutionEntityName => "opportunityclose"; 27 | 28 | protected override string ParentRecordLookupFieldName => "opportunityid"; 29 | 30 | protected override void SetResolutionEntity(EntityReference resolution) 31 | { 32 | OpportunityClose.Set(Context.ExecutionContext, resolution); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /CoreOperations/Opportunity/OpportunityLose.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Activities; 3 | using Microsoft.Xrm.Sdk; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | using Microsoft.Crm.Sdk.Messages; 6 | using UltimateWorkflowToolkit.Common; 7 | 8 | namespace UltimateWorkflowToolkit.CoreOperations 9 | { 10 | public class OpportunityLose : CrmWorkflowBase 11 | { 12 | #region Input/Output Parameters 13 | 14 | [Input("Opportunity")] 15 | [ReferenceTarget("opportunity")] 16 | [RequiredArgument] 17 | public InArgument Opportunity { get; set; } 18 | 19 | [Input("Opportunity Status")] 20 | [AttributeTarget("opportunity", "statuscode")] 21 | [RequiredArgument] 22 | public InArgument OpportunityStatus { get; set; } 23 | 24 | [Input("Opportunity Close: Subject")] 25 | public InArgument Subject { get; set; } 26 | 27 | [Input("Opportunity Close: Actual Revenue")] 28 | [RequiredArgument] 29 | public InArgument ActualRevenue { get; set; } 30 | 31 | [Input("Opportunity Close: Close Date")] 32 | [RequiredArgument] 33 | public InArgument CloseDate { get; set; } 34 | 35 | [Input("Opportunity Close: Competitor")] 36 | [ReferenceTarget("competitor")] 37 | public InArgument Competitor { get; set; } 38 | 39 | [Input("Opportunity Close: Description")] 40 | public InArgument Description { get; set; } 41 | 42 | #endregion Input/Output Parameters 43 | 44 | protected override void ExecuteWorkflowLogic() 45 | { 46 | var opportunityClose = new Entity("opportunityclose") 47 | { 48 | ["subject"] = Subject.Get(Context.ExecutionContext), 49 | ["opportunityid"] = Opportunity.Get(Context.ExecutionContext), 50 | ["actualrevenue"] = ActualRevenue.Get(Context.ExecutionContext), 51 | ["actualend"] = CloseDate.Get(Context.ExecutionContext), 52 | ["competitorid"] = Competitor.Get(Context.ExecutionContext), 53 | ["description"] = Description.Get(Context.ExecutionContext) 54 | }; 55 | 56 | var loseOpportunityRequest = new LoseOpportunityRequest() 57 | { 58 | Status = OpportunityStatus.Get(Context.ExecutionContext), 59 | OpportunityClose = opportunityClose 60 | }; 61 | 62 | Context.UserService.Execute(loseOpportunityRequest); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /CoreOperations/Opportunity/OpportunityWin.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Activities; 3 | using Microsoft.Xrm.Sdk; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | using Microsoft.Crm.Sdk.Messages; 6 | using UltimateWorkflowToolkit.Common; 7 | 8 | namespace UltimateWorkflowToolkit.CoreOperations 9 | { 10 | public class OpportunityWin : CrmWorkflowBase 11 | { 12 | #region Input/Output Parameters 13 | 14 | [Input("Opportunity")] 15 | [ReferenceTarget("opportunity")] 16 | [RequiredArgument] 17 | public InArgument Opportunity { get; set; } 18 | 19 | [Input("Opportunity Status")] 20 | [AttributeTarget("opportunity", "statuscode")] 21 | [RequiredArgument] 22 | public InArgument OpportunityStatus { get; set; } 23 | 24 | [Input("Opportunity Close: Subject")] 25 | public InArgument Subject { get; set; } 26 | 27 | [Input("Opportunity Close: Actual Revenue")] 28 | [RequiredArgument] 29 | public InArgument ActualRevenue { get; set; } 30 | 31 | [Input("Opportunity Close: Close Date")] 32 | [RequiredArgument] 33 | public InArgument CloseDate { get; set; } 34 | 35 | [Input("Opportunity Close: Description")] 36 | public InArgument Description { get; set; } 37 | 38 | #endregion Input/Output Parameters 39 | 40 | protected override void ExecuteWorkflowLogic() 41 | { 42 | var opportunityClose = new Entity("opportunityclose") 43 | { 44 | ["subject"] = Subject.Get(Context.ExecutionContext), 45 | ["opportunityid"] = Opportunity.Get(Context.ExecutionContext), 46 | ["actualrevenue"] = ActualRevenue.Get(Context.ExecutionContext), 47 | ["actualend"] = CloseDate.Get(Context.ExecutionContext), 48 | ["description"] = Description.Get(Context.ExecutionContext) 49 | }; 50 | 51 | var winOpportunityRequest = new WinOpportunityRequest() 52 | { 53 | Status = OpportunityStatus.Get(Context.ExecutionContext), 54 | OpportunityClose = opportunityClose 55 | }; 56 | 57 | Context.UserService.Execute(winOpportunityRequest); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /CoreOperations/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Workflows")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Workflows")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("5280f778-9d91-4cfa-bdcc-05cf6f239a0d")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /CoreOperations/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace UltimateWorkflowToolkit.CoreOperations.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | 26 | [global::System.Configuration.ApplicationScopedSettingAttribute()] 27 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 28 | [global::System.Configuration.DefaultSettingValueAttribute("WORKFLOW")] 29 | public string CRMProjectType { 30 | get { 31 | return ((string)(this["CRMProjectType"])); 32 | } 33 | } 34 | 35 | [global::System.Configuration.ApplicationScopedSettingAttribute()] 36 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 37 | [global::System.Configuration.DefaultSettingValueAttribute("")] 38 | public string CRMTestType { 39 | get { 40 | return ((string)(this["CRMTestType"])); 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /CoreOperations/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | WORKFLOW 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /CoreOperations/Quote/QuoteAddDetail.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Activities; 3 | using Microsoft.Xrm.Sdk; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | using UltimateWorkflowToolkit.CoreOperations.Base; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations.Quote 8 | { 9 | public class QuoteAddDetail : AddDetailWorkflowExtensionBase 10 | { 11 | #region Input Arguments 12 | 13 | [Input("Quote")] 14 | [ReferenceTarget("quote")] 15 | [RequiredArgument] 16 | public InArgument Quote { get; set; } 17 | 18 | [Input("Freight Terms")] 19 | [AttributeTarget("quotedetail", "shipto_freighttermscode")] 20 | public InArgument ShipToFreightTerms { get; set; } 21 | 22 | [Input("Requested Delivery Date")] 23 | public InArgument RequestDeliveryBy { get; set; } 24 | 25 | [Input("Ship To Contact Name")] 26 | public InArgument ShipToContactName { get; set; } 27 | 28 | #endregion Input Arguments 29 | 30 | protected override string ProductEntityName => "quotedetail"; 31 | protected override string ParentEntityLookupFieldName => "quoteid"; 32 | protected override EntityReference ParentEntity => Quote.Get(Context.ExecutionContext); 33 | 34 | protected override void ProcessAdditionalFields(ref Entity record) 35 | { 36 | record["shipto_freighttermscode"] = ShipToFreightTerms.Get(Context.ExecutionContext); 37 | record["requestdeliveryby"] = RequestDeliveryBy.Get(Context.ExecutionContext); 38 | record["shipto_contactname"] = ShipToContactName.Get(Context.ExecutionContext); 39 | 40 | base.ProcessAdditionalFields(ref record); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /CoreOperations/Quote/QuoteClose.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Activities; 3 | using Microsoft.Xrm.Sdk; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | using Microsoft.Crm.Sdk.Messages; 6 | using UltimateWorkflowToolkit.Common; 7 | 8 | namespace UltimateWorkflowToolkit.CoreOperations 9 | { 10 | public class QuoteClose : CrmWorkflowBase 11 | { 12 | #region Input/Output Parameters 13 | 14 | [Input("Quote")] 15 | [ReferenceTarget("quote")] 16 | [RequiredArgument] 17 | public InArgument Quote { get; set; } 18 | 19 | [Input("Quote Status")] 20 | [AttributeTarget("quote", "statuscode")] 21 | [RequiredArgument] 22 | public InArgument QuoteStatus { get; set; } 23 | 24 | [Input("Quote Close: Subject")] 25 | public InArgument Subject { get; set; } 26 | 27 | [Input("Quote Close: Close Date")] 28 | [RequiredArgument] 29 | public InArgument CloseDate { get; set; } 30 | 31 | [Input("Quote Close: Description")] 32 | public InArgument Description { get; set; } 33 | 34 | #endregion Input/Output Parameters 35 | 36 | protected override void ExecuteWorkflowLogic() 37 | { 38 | var quoteCloseRequest = new CloseQuoteRequest() 39 | { 40 | Status = QuoteStatus.Get(Context.ExecutionContext), 41 | QuoteClose = new Entity("quoteclose") 42 | { 43 | ["subject"] = Subject.Get(Context.ExecutionContext), 44 | ["quoteid"] = Quote.Get(Context.ExecutionContext), 45 | ["actualend"] = CloseDate.Get(Context.ExecutionContext), 46 | ["description"] = Description.Get(Context.ExecutionContext) 47 | } 48 | }; 49 | 50 | Context.UserService.Execute(quoteCloseRequest); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /CoreOperations/Quote/QuoteConvertToSalesOrder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Activities; 3 | using Microsoft.Xrm.Sdk; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | using Microsoft.Crm.Sdk.Messages; 6 | using Microsoft.Xrm.Sdk.Query; 7 | using UltimateWorkflowToolkit.Common; 8 | 9 | namespace UltimateWorkflowToolkit.CoreOperations 10 | { 11 | public class QuoteConvertToSalesOrder: CrmWorkflowBase 12 | { 13 | #region Input/Output Parameters 14 | 15 | [Input("Quote")] 16 | [ReferenceTarget("quote")] 17 | [RequiredArgument] 18 | public InArgument Quote { get; set; } 19 | 20 | [Input("Quote Status")] 21 | [AttributeTarget("quote", "statuscode")] 22 | [RequiredArgument] 23 | public InArgument QuoteStatus { get; set; } 24 | 25 | [Input("Quote Close: Subject")] 26 | public InArgument Subject { get; set; } 27 | 28 | [Input("Quote Close: Close Date")] 29 | [RequiredArgument] 30 | public InArgument CloseDate { get; set; } 31 | 32 | [Input("Quote Close: Description")] 33 | public InArgument Description { get; set; } 34 | 35 | [Output("Sales Order")] 36 | [ReferenceTarget("salesorder")] 37 | public OutArgument SalesOrder { get; set; } 38 | 39 | #endregion Input/Output Parameters 40 | 41 | protected override void ExecuteWorkflowLogic() 42 | { 43 | var convertQuoteToSalesOrderRequest = new ConvertQuoteToSalesOrderRequest() 44 | { 45 | ColumnSet = new ColumnSet("salesorderid"), 46 | QuoteCloseDate = CloseDate.Get(Context.ExecutionContext), 47 | QuoteCloseDescription = Description.Get(Context.ExecutionContext), 48 | QuoteCloseStatus = QuoteStatus.Get(Context.ExecutionContext), 49 | QuoteCloseSubject = Subject.Get(Context.ExecutionContext), 50 | QuoteId = Quote.Get(Context.ExecutionContext).Id 51 | }; 52 | 53 | var convertQuoteToSalesOrderResponse = 54 | (ConvertQuoteToSalesOrderResponse) Context.UserService.Execute(convertQuoteToSalesOrderRequest); 55 | 56 | SalesOrder.Set(Context.ExecutionContext, convertQuoteToSalesOrderResponse.Entity.ToEntityReference()); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /CoreOperations/Quote/QuoteGetProductsFromOpportunity.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using UltimateWorkflowToolkit.CoreOperations.Base; 5 | 6 | namespace UltimateWorkflowToolkit.CoreOperations 7 | { 8 | public class QuoteGetProductsFromOpportunity: CopyDetailsWorkflowsBase 9 | { 10 | #region Input/Output Parameters 11 | 12 | [Input("Quote")] 13 | [ReferenceTarget("quote")] 14 | [RequiredArgument] 15 | public InArgument Quote { get; set; } 16 | 17 | [Input("Opportunity")] 18 | [ReferenceTarget("opportunity")] 19 | [RequiredArgument] 20 | public InArgument Opportunity { get; set; } 21 | 22 | #endregion Input/Output Parameters 23 | 24 | protected override EntityReference SourceEntityParent => Opportunity.Get(Context.ExecutionContext); 25 | 26 | protected override EntityReference TargetEntityParent => Quote.Get(Context.ExecutionContext); 27 | 28 | protected override string SourceEntity => "opportunityproduct"; 29 | protected override string SourceEntityLookupFieldName => "opportunityid"; 30 | protected override string TargetEntity => "quotedetail"; 31 | protected override string TargetEntityLookupFieldName => "quoteid"; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /CoreOperations/Quote/QuoteGetResolution.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Activities; 3 | using Microsoft.Xrm.Sdk; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | using UltimateWorkflowToolkit.CoreOperations.Base; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations 8 | { 9 | public class QuoteGetResolution: GetResolutionWorkflowBase 10 | { 11 | #region Input/Output Parameters 12 | 13 | [Input("Quote")] 14 | [ReferenceTarget("quote")] 15 | [RequiredArgument] 16 | public InArgument Quote { get; set; } 17 | 18 | [Output("Quote Close")] 19 | [ReferenceTarget("quoteclose")] 20 | public OutArgument QuoteClose { get; set; } 21 | 22 | #endregion Input/Output Parameters 23 | 24 | protected override Guid ParentRecordId => Quote.Get(Context.ExecutionContext).Id; 25 | 26 | protected override string ResolutionEntityName => "quoteclose"; 27 | 28 | protected override string ParentRecordLookupFieldName => "quoteid"; 29 | 30 | protected override void SetResolutionEntity(EntityReference resolution) 31 | { 32 | QuoteClose.Set(Context.ExecutionContext, resolution); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /CoreOperations/Quote/QuoteRevise.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using Microsoft.Crm.Sdk.Messages; 5 | using Microsoft.Xrm.Sdk.Query; 6 | using UltimateWorkflowToolkit.Common; 7 | 8 | namespace UltimateWorkflowToolkit.CoreOperations 9 | { 10 | public class QuoteRevise: CrmWorkflowBase 11 | { 12 | #region Input/Output Parameters 13 | 14 | [Input("Quote")] 15 | [ReferenceTarget("quote")] 16 | [RequiredArgument] 17 | public InArgument Quote { get; set; } 18 | 19 | [Output("Revised Quote")] 20 | [ReferenceTarget("quote")] 21 | public OutArgument RevisedQuote { get; set; } 22 | 23 | #endregion Input/Output Parameters 24 | 25 | protected override void ExecuteWorkflowLogic() 26 | { 27 | var reviseQuoteRequest = new ReviseQuoteRequest() 28 | { 29 | ColumnSet = new ColumnSet("quoteid"), 30 | QuoteId = Quote.Get(Context.ExecutionContext).Id 31 | }; 32 | 33 | var reviseQuoteResponse = (ReviseQuoteResponse) Context.UserService.Execute(reviseQuoteRequest); 34 | 35 | RevisedQuote.Set(Context.ExecutionContext, reviseQuoteResponse.Entity.ToEntityReference()); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /CoreOperations/Quote/QuoteWin.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Activities; 3 | using Microsoft.Xrm.Sdk; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | using Microsoft.Crm.Sdk.Messages; 6 | using UltimateWorkflowToolkit.Common; 7 | 8 | namespace UltimateWorkflowToolkit.CoreOperations 9 | { 10 | public class QuoteWin: CrmWorkflowBase 11 | { 12 | #region Input/Output Parameters 13 | 14 | [Input("Quote")] 15 | [ReferenceTarget("quote")] 16 | [RequiredArgument] 17 | public InArgument Quote { get; set; } 18 | 19 | [Input("Quote Status")] 20 | [AttributeTarget("quote", "statuscode")] 21 | [RequiredArgument] 22 | public InArgument QuoteStatus { get; set; } 23 | 24 | [Input("Quote Close: Subject")] 25 | public InArgument Subject { get; set; } 26 | 27 | [Input("Quote Close: Close Date")] 28 | [RequiredArgument] 29 | public InArgument CloseDate { get; set; } 30 | 31 | [Input("Quote Close: Description")] 32 | public InArgument Description { get; set; } 33 | 34 | #endregion Input/Output Parameters 35 | 36 | protected override void ExecuteWorkflowLogic() 37 | { 38 | var winQuoteRecuest = new WinQuoteRequest() 39 | { 40 | Status = QuoteStatus.Get(Context.ExecutionContext), 41 | QuoteClose = new Entity("quoteclose") 42 | { 43 | ["subject"] = Subject.Get(Context.ExecutionContext), 44 | ["quoteid"] = Quote.Get(Context.ExecutionContext), 45 | ["actualend"] = CloseDate.Get(Context.ExecutionContext), 46 | ["description"] = Description.Get(Context.ExecutionContext) 47 | } 48 | }; 49 | 50 | Context.UserService.Execute(winQuoteRecuest); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /CoreOperations/RequestBuilder/BuildRequestFromEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Activities; 3 | using System.Collections.Generic; 4 | using Microsoft.Xrm.Sdk; 5 | using Microsoft.Xrm.Sdk.Query; 6 | using Microsoft.Xrm.Sdk.Workflow; 7 | using UltimateWorkflowToolkit.CoreOperations.Base; 8 | 9 | namespace UltimateWorkflowToolkit.CoreOperations.RequestBuilder 10 | { 11 | public class BuildRequestFromEntity: BuildRequestWorkflowBase 12 | { 13 | #region Inputs 14 | 15 | [Input("Source Entity")] 16 | [RequiredArgument] 17 | public InArgument RecordId { get; set; } 18 | 19 | [Input("Source Entity Fields")] 20 | [RequiredArgument] 21 | public InArgument SourceFields { get; set; } 22 | 23 | [Input("Destination Request Fields")] 24 | [RequiredArgument] 25 | public InArgument DestinationFields { get; set; } 26 | 27 | #endregion Inputs 28 | 29 | protected override void BuildRequest(ref Dictionary request) 30 | { 31 | var sourceFields = SourceFields.Get(Context.ExecutionContext) 32 | .Split(new[] {"|"}, StringSplitOptions.RemoveEmptyEntries); 33 | var destinationFields = DestinationFields.Get(Context.ExecutionContext) 34 | .Split(new[] {"|"}, StringSplitOptions.RemoveEmptyEntries); 35 | 36 | if (sourceFields.Length != destinationFields.Length) 37 | throw new InvalidPluginExecutionException("Number of Source Fields is not equal to number of Destination Fields"); 38 | 39 | var entityReference = ConvertToEntityReference(RecordId.Get(Context.ExecutionContext)); 40 | 41 | var sourceRecord = Context.SystemService.Retrieve(entityReference.LogicalName, entityReference.Id, 42 | new ColumnSet(sourceFields)); 43 | 44 | for (var i = 0; i < sourceFields.Length; i++) 45 | { 46 | object targetFieldValue = null; 47 | 48 | if (sourceRecord.Contains(sourceFields[i])) 49 | targetFieldValue = sourceRecord[sourceFields[i]]; 50 | 51 | request.Add(destinationFields[i], targetFieldValue); 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /CoreOperations/RequestBuilder/SetBooleanField.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using System.Collections.Generic; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using UltimateWorkflowToolkit.CoreOperations.Base; 5 | 6 | namespace UltimateWorkflowToolkit.CoreOperations.RequestBuilder 7 | { 8 | public class SetBooleanField: SetFieldWorkflowBase 9 | { 10 | #region Inputs 11 | 12 | [Input("Field Value")] 13 | [RequiredArgument] 14 | public InArgument FieldValue { get; set; } 15 | 16 | #endregion Inputs 17 | 18 | protected override void AddField(ref Dictionary dictionary, string fieldName) 19 | { 20 | dictionary.Add(fieldName, FieldValue.Get(Context.ExecutionContext)); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /CoreOperations/RequestBuilder/SetDateTimeField.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Activities; 3 | using System.Collections.Generic; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | using UltimateWorkflowToolkit.CoreOperations.Base; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations.RequestBuilder 8 | { 9 | public class SetDateTimeField: SetFieldWorkflowBase 10 | { 11 | #region Inputs 12 | 13 | [Input("Field Value")] 14 | [RequiredArgument] 15 | public InArgument FieldValue { get; set; } 16 | 17 | #endregion Inputs 18 | 19 | protected override void AddField(ref Dictionary dictionary, string fieldName) 20 | { 21 | dictionary.Add(fieldName, FieldValue.Get(Context.ExecutionContext)); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /CoreOperations/RequestBuilder/SetDecimalField.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using System.Collections.Generic; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using UltimateWorkflowToolkit.CoreOperations.Base; 5 | 6 | namespace UltimateWorkflowToolkit.CoreOperations.RequestBuilder 7 | { 8 | public class SetDecimalField: SetFieldWorkflowBase 9 | { 10 | #region Inputs 11 | 12 | [Input("Field Value")] 13 | [RequiredArgument] 14 | public InArgument FieldValue { get; set; } 15 | 16 | #endregion Inputs 17 | 18 | protected override void AddField(ref Dictionary dictionary, string fieldName) 19 | { 20 | dictionary.Add(fieldName, FieldValue.Get(Context.ExecutionContext)); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /CoreOperations/RequestBuilder/SetFieldToNull.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using UltimateWorkflowToolkit.CoreOperations.Base; 3 | 4 | namespace UltimateWorkflowToolkit.CoreOperations.RequestBuilder 5 | { 6 | public class SetFieldToNull: SetFieldWorkflowBase 7 | { 8 | protected override void AddField(ref Dictionary dictionary, string fieldName) 9 | { 10 | dictionary.Add(fieldName, null); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /CoreOperations/RequestBuilder/SetIntField.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using System.Collections.Generic; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using UltimateWorkflowToolkit.CoreOperations.Base; 5 | 6 | namespace UltimateWorkflowToolkit.CoreOperations.RequestBuilder 7 | { 8 | public class SetIntField: SetFieldWorkflowBase 9 | { 10 | #region Inputs 11 | 12 | [Input("Field Value")] 13 | [RequiredArgument] 14 | public InArgument FieldValue { get; set; } 15 | 16 | #endregion Inputs 17 | 18 | protected override void AddField(ref Dictionary dictionary, string fieldName) 19 | { 20 | dictionary.Add(fieldName, FieldValue.Get(Context.ExecutionContext)); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /CoreOperations/RequestBuilder/SetLookupField.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using System.Collections.Generic; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using UltimateWorkflowToolkit.CoreOperations.Base; 5 | 6 | namespace UltimateWorkflowToolkit.CoreOperations.RequestBuilder 7 | { 8 | public class SetLookupField: SetFieldWorkflowBase 9 | { 10 | #region Inputs 11 | 12 | [Input("Field Value")] 13 | public InArgument FieldValue { get; set; } 14 | 15 | #endregion Inputs 16 | 17 | protected override void AddField(ref Dictionary dictionary, string fieldName) 18 | { 19 | var lookup = ConvertToEntityReference(FieldValue.Get(Context.ExecutionContext)); 20 | dictionary.Add(fieldName, lookup); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /CoreOperations/RequestBuilder/SetLookupFieldFromQuery.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xrm.Sdk.Workflow; 2 | using System; 3 | using System.Activities; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using Microsoft.Xrm.Sdk.Query; 9 | using UltimateWorkflowToolkit.CoreOperations.Base; 10 | 11 | namespace UltimateWorkflowToolkit.CoreOperations.RequestBuilder 12 | { 13 | public class SetLookupFieldFromQuery: SetFieldWorkflowBase 14 | { 15 | #region Inputs 16 | 17 | [Input("Fetch Xml Query")] 18 | [RequiredArgument] 19 | public InArgument FetchXmlQuery { get; set; } 20 | 21 | [Input("Set to null on empty results")] 22 | [RequiredArgument] 23 | public InArgument IsSetToNull { get; set; } 24 | 25 | #endregion Inputs 26 | 27 | protected override void AddField(ref Dictionary request, string fieldName) 28 | { 29 | var fetchXml = FetchXmlQuery.Get(Context.ExecutionContext); 30 | 31 | var record = Context.UserService.RetrieveMultiple(new FetchExpression(fetchXml)).Entities 32 | .FirstOrDefault(); 33 | 34 | if (record != null) 35 | { 36 | request.Add(fieldName, record.ToEntityReference()); 37 | } 38 | else if (IsSetToNull.Get(Context.ExecutionContext)) 39 | { 40 | request.Add(fieldName, null); 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /CoreOperations/RequestBuilder/SetMoneyField.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using System.Collections.Generic; 3 | using Microsoft.Xrm.Sdk; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | using UltimateWorkflowToolkit.CoreOperations.Base; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations.RequestBuilder 8 | { 9 | public class SetMoneyField: SetFieldWorkflowBase 10 | { 11 | #region Inputs 12 | 13 | [Input("Field Value")] 14 | public InArgument FieldValue { get; set; } 15 | 16 | #endregion Inputs 17 | 18 | protected override void AddField(ref Dictionary dictionary, string fieldName) 19 | { 20 | dictionary.Add(fieldName, FieldValue.Get(Context.ExecutionContext)); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /CoreOperations/RequestBuilder/SetOptionSetField.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using System.Collections.Generic; 3 | using Microsoft.Xrm.Sdk; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | using UltimateWorkflowToolkit.CoreOperations.Base; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations.RequestBuilder 8 | { 9 | public class SetOptionSetField: SetFieldWorkflowBase 10 | { 11 | #region Inputs 12 | 13 | [Input("Field Value")] 14 | public InArgument FieldValue { get; set; } 15 | 16 | #endregion Inputs 17 | 18 | protected override void AddField(ref Dictionary dictionary, string fieldName) 19 | { 20 | dictionary.Add(fieldName, new OptionSetValue(FieldValue.Get(Context.ExecutionContext))); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /CoreOperations/RequestBuilder/SetStringField.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using System.Collections.Generic; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using UltimateWorkflowToolkit.CoreOperations.Base; 5 | 6 | namespace UltimateWorkflowToolkit.CoreOperations.RequestBuilder 7 | { 8 | public class SetStringField: SetFieldWorkflowBase 9 | { 10 | #region Inputs 11 | 12 | [Input("Field Value")] 13 | public InArgument FieldValue { get; set; } 14 | 15 | #endregion Inputs 16 | 17 | protected override void AddField(ref Dictionary dictionary, string fieldName) 18 | { 19 | dictionary.Add(fieldName, FieldValue.Get(Context.ExecutionContext)); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /CoreOperations/SalesOrder/SalesOrderAddDetail.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Activities; 3 | using Microsoft.Xrm.Sdk; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | using UltimateWorkflowToolkit.CoreOperations.Base; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations.SalesOrder 8 | { 9 | public class SalesOrderAddDetail : AddDetailWorkflowExtensionBase 10 | { 11 | #region Inputs 12 | 13 | [Input("Order")] 14 | [ReferenceTarget("salesorder")] 15 | [RequiredArgument] 16 | public InArgument SalesOrder { get; set; } 17 | 18 | [Input("Freight Terms")] 19 | [AttributeTarget("salesorderdetail", "shipto_freighttermscode")] 20 | public InArgument ShipToFreightTerms { get; set; } 21 | 22 | [Input("Ship To Contact Name")] 23 | public InArgument ShipToContactName { get; set; } 24 | 25 | [Input("Quantity Back Ordered")] 26 | public InArgument QuantityBackOrdered { get; set; } 27 | 28 | [Input("Quantity Canceled")] 29 | public InArgument QuantityCancelled { get; set; } 30 | 31 | [Input("Quantity Shipped")] 32 | public InArgument QuantityShipped { get; set; } 33 | 34 | [Input("Requested Delivery Date")] 35 | public InArgument RequestDeliveryBy { get; set; } 36 | 37 | [Input("Copied")] 38 | [Default("False")] 39 | public InArgument IsCopied { get; set; } 40 | 41 | #endregion Inputs 42 | 43 | protected override string ProductEntityName => "salesorderdetail"; 44 | protected override string ParentEntityLookupFieldName => "salesorderid"; 45 | protected override EntityReference ParentEntity => SalesOrder.Get(Context.ExecutionContext); 46 | 47 | protected override void ProcessAdditionalFields(ref Entity record) 48 | { 49 | record["shipto_freighttermscode"] = ShipToFreightTerms.Get(Context.ExecutionContext); 50 | record["shipto_contactname"] = ShipToContactName.Get(Context.ExecutionContext); 51 | record["quantitybackordered"] = QuantityBackOrdered.Get(Context.ExecutionContext); 52 | record["quantitycancelled"] = QuantityCancelled.Get(Context.ExecutionContext); 53 | record["quantityshipped"] = QuantityShipped.Get(Context.ExecutionContext); 54 | record["requestdeliveryby"] = RequestDeliveryBy.Get(Context.ExecutionContext); 55 | record["iscopied"] = IsCopied.Get(Context.ExecutionContext); 56 | 57 | base.ProcessAdditionalFields(ref record); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /CoreOperations/SalesOrder/SalesOrderClose.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Activities; 3 | using Microsoft.Xrm.Sdk; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | using Microsoft.Crm.Sdk.Messages; 6 | using UltimateWorkflowToolkit.Common; 7 | 8 | namespace UltimateWorkflowToolkit.CoreOperations 9 | { 10 | public class SalesOrderClose : CrmWorkflowBase 11 | { 12 | #region Input/Output Parameters 13 | 14 | [Input("Order")] 15 | [ReferenceTarget("salesorder")] 16 | [RequiredArgument] 17 | public InArgument SalesOrder { get; set; } 18 | 19 | [Input("Order Status")] 20 | [AttributeTarget("salesorder", "statuscode")] 21 | [RequiredArgument] 22 | public InArgument SalesOrderStatus { get; set; } 23 | 24 | [Input("Order Close: Subject")] 25 | public InArgument Subject { get; set; } 26 | 27 | [Input("Order Close: Close Date")] 28 | [RequiredArgument] 29 | public InArgument CloseDate { get; set; } 30 | 31 | [Input("Order Close: Description")] 32 | public InArgument Description { get; set; } 33 | 34 | #endregion Input/Output Parameters 35 | 36 | protected override void ExecuteWorkflowLogic() 37 | { 38 | var cancelSalesOrderRequest = new CancelSalesOrderRequest() 39 | { 40 | Status = SalesOrderStatus.Get(Context.ExecutionContext), 41 | OrderClose = new Entity("orderclose") 42 | { 43 | ["subject"] = Subject.Get(Context.ExecutionContext), 44 | ["salesorderid"] = SalesOrder.Get(Context.ExecutionContext), 45 | ["actualend"] = CloseDate.Get(Context.ExecutionContext), 46 | ["description"] = Description.Get(Context.ExecutionContext) 47 | } 48 | }; 49 | 50 | Context.UserService.Execute(cancelSalesOrderRequest); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /CoreOperations/SalesOrder/SalesOrderConvertToInvoice.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using UltimateWorkflowToolkit.CoreOperations.Base; 5 | 6 | namespace UltimateWorkflowToolkit.CoreOperations 7 | { 8 | public class SalesOrderConvertToInvoice: CreateChildFromParentWorkflowBase 9 | { 10 | #region Input/Output Parameters 11 | 12 | [Input("Order")] 13 | [ReferenceTarget("salesorder")] 14 | [RequiredArgument] 15 | public InArgument SalesOrder { get; set; } 16 | 17 | [Output("Invoice")] 18 | [ReferenceTarget("invoice")] 19 | public OutArgument Invoice { get; set; } 20 | 21 | #endregion Input/Output Parameters 22 | 23 | protected override EntityReference SourceEntity => SalesOrder.Get(Context.ExecutionContext); 24 | 25 | protected override void SetTargetEntity(EntityReference target) 26 | { 27 | Invoice.Set(Context.ExecutionContext, target); 28 | } 29 | 30 | protected override string SourceEntityChild => "salesorderdetail"; 31 | protected override string SourceEntityLookupFieldName => "salesorderid"; 32 | protected override string TargetEntity => "invoice"; 33 | protected override string TargetEntityChild => "invoicedetail"; 34 | protected override string TargetEntityLookupFieldName => "invoiceid"; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /CoreOperations/SalesOrder/SalesOrderFulfill.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Activities; 3 | using Microsoft.Xrm.Sdk; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | using Microsoft.Crm.Sdk.Messages; 6 | using UltimateWorkflowToolkit.Common; 7 | 8 | namespace UltimateWorkflowToolkit.CoreOperations 9 | { 10 | public class SalesOrderFulfill: CrmWorkflowBase 11 | { 12 | #region Input/Output Parameters 13 | 14 | [Input("Order")] 15 | [ReferenceTarget("salesorder")] 16 | [RequiredArgument] 17 | public InArgument SalesOrder { get; set; } 18 | 19 | [Input("Order Status")] 20 | [AttributeTarget("salesorder", "statuscode")] 21 | [RequiredArgument] 22 | public InArgument SalesOrderStatus { get; set; } 23 | 24 | [Input("Order Close: Subject")] 25 | public InArgument Subject { get; set; } 26 | 27 | [Input("Order Close: Close Date")] 28 | [RequiredArgument] 29 | public InArgument CloseDate { get; set; } 30 | 31 | [Input("Order Close: Description")] 32 | public InArgument Description { get; set; } 33 | 34 | #endregion Input/Output Parameters 35 | 36 | protected override void ExecuteWorkflowLogic() 37 | { 38 | var fulfillSalesOrderRequest = new FulfillSalesOrderRequest() 39 | { 40 | Status = SalesOrderStatus.Get(Context.ExecutionContext), 41 | OrderClose = new Entity("orderclose") 42 | { 43 | ["subject"] = Subject.Get(Context.ExecutionContext), 44 | ["salesorderid"] = SalesOrder.Get(Context.ExecutionContext), 45 | ["actualend"] = CloseDate.Get(Context.ExecutionContext), 46 | ["description"] = Description.Get(Context.ExecutionContext) 47 | } 48 | }; 49 | 50 | Context.UserService.Execute(fulfillSalesOrderRequest); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /CoreOperations/SalesOrder/SalesOrderGetProductsFromOpportunity.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using UltimateWorkflowToolkit.CoreOperations.Base; 5 | 6 | namespace UltimateWorkflowToolkit.CoreOperations 7 | { 8 | public class SalesOrderGetProductsFromOpportunity : CopyDetailsWorkflowsBase 9 | { 10 | 11 | #region Input/Output Parameters 12 | 13 | [Input("Order")] 14 | [ReferenceTarget("salesorder")] 15 | [RequiredArgument] 16 | public InArgument SalesOrder { get; set; } 17 | 18 | [Input("Opportunity")] 19 | [ReferenceTarget("opportunity")] 20 | [RequiredArgument] 21 | public InArgument Opportunity { get; set; } 22 | 23 | #endregion Input/Output Parameters 24 | 25 | protected override EntityReference SourceEntityParent => Opportunity.Get(Context.ExecutionContext); 26 | 27 | protected override EntityReference TargetEntityParent => SalesOrder.Get(Context.ExecutionContext); 28 | 29 | protected override string SourceEntity => "opportunityproduct"; 30 | protected override string SourceEntityLookupFieldName => "opportunityid"; 31 | protected override string TargetEntity => "salesorderdetail"; 32 | protected override string TargetEntityLookupFieldName => "salesorderid"; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /CoreOperations/SalesOrder/SalesOrderGetResolution.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Activities; 3 | using Microsoft.Xrm.Sdk; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | using UltimateWorkflowToolkit.CoreOperations.Base; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations 8 | { 9 | public class SalesOrderGetResolution: GetResolutionWorkflowBase 10 | { 11 | #region Input/Output Parameters 12 | 13 | [Input("Order")] 14 | [ReferenceTarget("salesorder")] 15 | [RequiredArgument] 16 | public InArgument Order { get; set; } 17 | 18 | [Output("Order Close")] 19 | [ReferenceTarget("orderclose")] 20 | public OutArgument OrderClose { get; set; } 21 | 22 | #endregion Input/Output Parameters 23 | 24 | protected override Guid ParentRecordId => Order.Get(Context.ExecutionContext).Id; 25 | 26 | protected override string ResolutionEntityName => "orderclose"; 27 | 28 | protected override string ParentRecordLookupFieldName => "salesorderid"; 29 | 30 | protected override void SetResolutionEntity(EntityReference resolution) 31 | { 32 | OrderClose.Set(Context.ExecutionContext, resolution); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /CoreOperations/SalesOrder/SalesOrderLockPricing.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using Microsoft.Crm.Sdk.Messages; 5 | using UltimateWorkflowToolkit.Common; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations 8 | { 9 | public class SalesOrderLockPricing : CrmWorkflowBase 10 | { 11 | #region Input/Output Parameters 12 | 13 | [Input("Order")] 14 | [ReferenceTarget("salesorder")] 15 | [RequiredArgument] 16 | public InArgument SalesOrder { get; set; } 17 | 18 | #endregion Input/Output Parameters 19 | 20 | protected override void ExecuteWorkflowLogic() 21 | { 22 | var lockSalesOrderPricingRequest = new LockSalesOrderPricingRequest() 23 | { 24 | SalesOrderId = SalesOrder.Get(Context.ExecutionContext).Id 25 | }; 26 | 27 | Context.UserService.Execute(lockSalesOrderPricingRequest); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /CoreOperations/SalesOrder/SalesOrderUnlockPricing.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using Microsoft.Crm.Sdk.Messages; 5 | using UltimateWorkflowToolkit.Common; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations 8 | { 9 | public class SalesOrderUnlockPricing : CrmWorkflowBase 10 | { 11 | #region Input/Output Parameters 12 | 13 | [Input("Order")] 14 | [ReferenceTarget("salesorder")] 15 | [RequiredArgument] 16 | public InArgument SalesOrder { get; set; } 17 | 18 | #endregion Input/Output Parameters 19 | 20 | protected override void ExecuteWorkflowLogic() 21 | { 22 | var unlockSalesOrderPricingRequest = new UnlockSalesOrderPricingRequest() 23 | { 24 | SalesOrderId = SalesOrder.Get(Context.ExecutionContext).Id 25 | }; 26 | 27 | Context.UserService.Execute(unlockSalesOrderPricingRequest); 28 | } 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /CoreOperations/Security/AddUserToRecordTeam.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using Microsoft.Crm.Sdk.Messages; 5 | using UltimateWorkflowToolkit.Common; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations.Security 8 | { 9 | public class AddUserToRecordTeam : CrmWorkflowBase 10 | { 11 | #region Input/Output Parameters 12 | 13 | [Input("Record Reference")] 14 | [RequiredArgument] 15 | public InArgument Record { get; set; } 16 | 17 | [Input("User")] 18 | [RequiredArgument] 19 | [ReferenceTarget("systemuser")] 20 | public InArgument User { get; set; } 21 | 22 | [Input("Team Template")] 23 | [RequiredArgument] 24 | [ReferenceTarget("teamtemplate")] 25 | public InArgument TeamTemplate { get; set; } 26 | 27 | #endregion Input/Output Parameters 28 | 29 | protected override void ExecuteWorkflowLogic() 30 | { 31 | var target = ConvertToEntityReference(Record.Get(Context.ExecutionContext)); 32 | 33 | Context.SystemService.Execute(new AddUserToRecordTeamRequest() 34 | { 35 | Record = target, 36 | SystemUserId = User.Get(Context.ExecutionContext).Id, 37 | TeamTemplateId = TeamTemplate.Get(Context.ExecutionContext).Id 38 | }); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /CoreOperations/Security/AddUserToTeam.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using Microsoft.Crm.Sdk.Messages; 5 | using UltimateWorkflowToolkit.Common; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations.Security 8 | { 9 | 10 | public class AddUserToTeam : CrmWorkflowBase 11 | { 12 | #region Input/Output Parameters 13 | 14 | [Input("User")] 15 | [RequiredArgument] 16 | [ReferenceTarget("systemuser")] 17 | public InArgument User { get; set; } 18 | 19 | [Input("Team")] 20 | [RequiredArgument] 21 | [ReferenceTarget("team")] 22 | public InArgument Team { get; set; } 23 | 24 | #endregion Input/Output Parameters 25 | 26 | protected override void ExecuteWorkflowLogic() 27 | { 28 | Context.SystemService.Execute(new AddMembersTeamRequest() 29 | { 30 | MemberIds = new[] { User.Get(Context.ExecutionContext).Id }, 31 | TeamId = Team.Get(Context.ExecutionContext).Id 32 | }); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /CoreOperations/Security/IsUserHasRole.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using Microsoft.Xrm.Sdk.Query; 5 | using UltimateWorkflowToolkit.Common; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations.Security 8 | { 9 | public class IsUserHasRole : CrmWorkflowBase 10 | { 11 | #region Input/Output Parameters 12 | 13 | [Input("User")] 14 | [RequiredArgument] 15 | [ReferenceTarget("systemuser")] 16 | public InArgument User { get; set; } 17 | 18 | [Input("Security Role")] 19 | [RequiredArgument] 20 | [ReferenceTarget("role")] 21 | public InArgument Role { get; set; } 22 | 23 | [Output("Is User Has Role")] 24 | public OutArgument HasRole { get; set; } 25 | 26 | #endregion Input/Output Parameters 27 | 28 | protected override void ExecuteWorkflowLogic() 29 | { 30 | var userQuery = new QueryExpression("systemuser") 31 | { 32 | ColumnSet = new ColumnSet(false) 33 | }; 34 | userQuery.Criteria.AddCondition("systemuserid", ConditionOperator.Equal, User.Get(Context.ExecutionContext).Id); 35 | 36 | var roleLink = userQuery.AddLink("systemuserroles", "systemuserid", "systemuserid"); 37 | roleLink = roleLink.AddLink("role", "roleid", "roleid"); 38 | roleLink.LinkCriteria.AddCondition("parentrootroleid", ConditionOperator.Equal, Role.Get(Context.ExecutionContext).Id); 39 | 40 | var hasRole = Context.SystemService.RetrieveMultiple(userQuery).Entities.Count != 0; 41 | 42 | HasRole.Set(Context.ExecutionContext, hasRole); 43 | } 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /CoreOperations/Security/IsUserMemberOfTeam.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using Microsoft.Xrm.Sdk.Query; 5 | using UltimateWorkflowToolkit.Common; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations.Security 8 | { 9 | public class IsUserMemberOfTeam: CrmWorkflowBase 10 | { 11 | #region Input/Output Parameters 12 | 13 | [Input("User")] 14 | [RequiredArgument] 15 | [ReferenceTarget("systemuser")] 16 | public InArgument User { get; set; } 17 | 18 | [Input("Team")] 19 | [RequiredArgument] 20 | [ReferenceTarget("team")] 21 | public InArgument Team { get; set; } 22 | 23 | [Output("Is Member")] 24 | public OutArgument IsMember { get; set; } 25 | 26 | #endregion Input/Output Parameters 27 | 28 | protected override void ExecuteWorkflowLogic() 29 | { 30 | var userQuery = new QueryExpression("systemuser") 31 | { 32 | ColumnSet = new ColumnSet(false) 33 | }; 34 | userQuery.Criteria.AddCondition("systemuserid", ConditionOperator.Equal, User.Get(Context.ExecutionContext).Id); 35 | 36 | var teamLink = userQuery.AddLink("teammembership", "systemuserid", "systemuserid"); 37 | teamLink.LinkCriteria.AddCondition("teamid", ConditionOperator.Equal, Team.Get(Context.ExecutionContext).Id); 38 | 39 | var isMember = Context.SystemService.RetrieveMultiple(userQuery).Entities.Count != 0; 40 | 41 | IsMember.Set(Context.ExecutionContext, isMember); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /CoreOperations/Security/IsUserTeamsHaveRole.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Query; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | using UltimateWorkflowToolkit.Common; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations.Security 8 | { 9 | public class IsUserTeamsHaveRole: CrmWorkflowBase 10 | { 11 | #region Input/Output Parameters 12 | 13 | [Input("User")] 14 | [RequiredArgument] 15 | [ReferenceTarget("systemuser")] 16 | public InArgument User { get; set; } 17 | 18 | [Input("Security Role")] 19 | [RequiredArgument] 20 | [ReferenceTarget("role")] 21 | public InArgument Role { get; set; } 22 | 23 | [Output("Is User's Teams Have Role")] 24 | public OutArgument HasRole { get; set; } 25 | 26 | #endregion Input/Output Parameters 27 | 28 | protected override void ExecuteWorkflowLogic() 29 | { 30 | var userQuery = new QueryExpression("systemuser") 31 | { 32 | ColumnSet = new ColumnSet(false) 33 | }; 34 | userQuery.Criteria.AddCondition("systemuserid", ConditionOperator.Equal, User.Get(Context.ExecutionContext).Id); 35 | 36 | var teamLink = userQuery.AddLink("teammembership", "systemuserid", "systemuserid"); 37 | var securityRoleLink = teamLink.AddLink("teamroles", "teamid", "teamid"); 38 | 39 | securityRoleLink.LinkCriteria.AddCondition("roleid", ConditionOperator.Equal, Role.Get(Context.ExecutionContext).Id); 40 | 41 | var hasRole = Context.SystemService.RetrieveMultiple(userQuery).Entities.Count != 0; 42 | 43 | HasRole.Set(Context.ExecutionContext, hasRole); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /CoreOperations/Security/RemoveUserFromRecordTeam.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using Microsoft.Crm.Sdk.Messages; 5 | using UltimateWorkflowToolkit.Common; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations.Security 8 | { 9 | public class RemoveUserFromRecordTeam : CrmWorkflowBase 10 | { 11 | #region Input/Output Parameters 12 | 13 | [Input("Record")] 14 | [RequiredArgument] 15 | public InArgument Record { get; set; } 16 | 17 | [Input("User")] 18 | [RequiredArgument] 19 | [ReferenceTarget("systemuser")] 20 | public InArgument User { get; set; } 21 | 22 | [Input("Team Template")] 23 | [RequiredArgument] 24 | [ReferenceTarget("teamtemplate")] 25 | public InArgument TeamTemplate { get; set; } 26 | 27 | #endregion Input/Output Parameters 28 | 29 | protected override void ExecuteWorkflowLogic() 30 | { 31 | var target = ConvertToEntityReference(Record.Get(Context.ExecutionContext)); 32 | 33 | Context.SystemService.Execute(new RemoveUserFromRecordTeamRequest() 34 | { 35 | Record = target, 36 | SystemUserId = User.Get(Context.ExecutionContext).Id, 37 | TeamTemplateId = TeamTemplate.Get(Context.ExecutionContext).Id 38 | }); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /CoreOperations/Security/RemoveUserFromTeam.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using Microsoft.Crm.Sdk.Messages; 5 | using UltimateWorkflowToolkit.Common; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations.Security 8 | { 9 | public class RemoveUserFromTeam : CrmWorkflowBase 10 | { 11 | #region Input/Output Parameters 12 | 13 | [Input("User")] 14 | [RequiredArgument] 15 | [ReferenceTarget("systemuser")] 16 | public InArgument User { get; set; } 17 | 18 | [Input("Team")] 19 | [RequiredArgument] 20 | [ReferenceTarget("team")] 21 | public InArgument Team { get; set; } 22 | 23 | #endregion Input/Output Parameters 24 | 25 | protected override void ExecuteWorkflowLogic() 26 | { 27 | Context.SystemService.Execute(new RemoveMembersTeamRequest() 28 | { 29 | MemberIds = new[] { User.Get(Context.ExecutionContext).Id }, 30 | TeamId = Team.Get(Context.ExecutionContext).Id 31 | }); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /CoreOperations/Security/ShareRecordWithTeam.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Crm.Sdk.Messages; 3 | using Microsoft.Xrm.Sdk; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | using UltimateWorkflowToolkit.Common; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations.Security 8 | { 9 | public class ShareRecordWithTeam : CrmWorkflowBase 10 | { 11 | #region Input/Output Parameters 12 | 13 | [Input("Record Reference")] 14 | [RequiredArgument] 15 | public InArgument Record { get; set; } 16 | 17 | [Input("Team")] 18 | [RequiredArgument] 19 | [ReferenceTarget("team")] 20 | public InArgument Team { get; set; } 21 | 22 | [Input("Read Access")] 23 | [RequiredArgument] 24 | [Default("False")] 25 | public InArgument ReadAccess { get; set; } 26 | 27 | [Input("Write Access")] 28 | [RequiredArgument] 29 | [Default("False")] 30 | public InArgument WriteAccess { get; set; } 31 | 32 | [Input("Delete Access")] 33 | [RequiredArgument] 34 | [Default("False")] 35 | public InArgument DeleteAccess { get; set; } 36 | 37 | [Input("Append Access")] 38 | [RequiredArgument] 39 | [Default("False")] 40 | public InArgument AppendAccess { get; set; } 41 | 42 | [Input("Append To Access")] 43 | [RequiredArgument] 44 | [Default("False")] 45 | public InArgument AppendToAccess { get; set; } 46 | 47 | [Input("Assign Access")] 48 | [RequiredArgument] 49 | [Default("False")] 50 | public InArgument AssignAccess { get; set; } 51 | 52 | [Input("Share Access")] 53 | [RequiredArgument] 54 | [Default("False")] 55 | public InArgument ShareAccess { get; set; } 56 | 57 | #endregion Input/Output Parameters 58 | 59 | protected override void ExecuteWorkflowLogic() 60 | { 61 | var target = ConvertToEntityReference(Record.Get(Context.ExecutionContext)); 62 | 63 | #region Build Sharing Mask 64 | 65 | var rights = AccessRights.None; 66 | 67 | if (ReadAccess.Get(Context.ExecutionContext)) 68 | { 69 | rights |= AccessRights.ReadAccess; 70 | } 71 | 72 | if (WriteAccess.Get(Context.ExecutionContext)) 73 | { 74 | rights |= AccessRights.WriteAccess; 75 | } 76 | 77 | if (DeleteAccess.Get(Context.ExecutionContext)) 78 | { 79 | rights |= AccessRights.DeleteAccess; 80 | } 81 | 82 | if (AppendAccess.Get(Context.ExecutionContext)) 83 | { 84 | rights |= AccessRights.AppendAccess; 85 | } 86 | 87 | if (AppendToAccess.Get(Context.ExecutionContext)) 88 | { 89 | rights |= AccessRights.AppendToAccess; 90 | } 91 | 92 | if (AssignAccess.Get(Context.ExecutionContext)) 93 | { 94 | rights |= AccessRights.AssignAccess; 95 | } 96 | 97 | if (ShareAccess.Get(Context.ExecutionContext)) 98 | { 99 | rights |= AccessRights.ShareAccess; 100 | } 101 | 102 | #endregion Build Sharing Mask 103 | 104 | Context.SystemService.Execute(new GrantAccessRequest() 105 | { 106 | PrincipalAccess = new PrincipalAccess() 107 | { 108 | AccessMask = rights, 109 | Principal = Team.Get(Context.ExecutionContext) 110 | }, 111 | Target = target 112 | }); 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /CoreOperations/Security/ShareRecordWithUser.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Crm.Sdk.Messages; 3 | using Microsoft.Xrm.Sdk; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | using UltimateWorkflowToolkit.Common; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations.Security 8 | { 9 | public class ShareRecordWithUser : CrmWorkflowBase 10 | { 11 | #region Input/Output Parameters 12 | 13 | [Input("Record Reference")] 14 | [RequiredArgument] 15 | public InArgument Record { get; set; } 16 | 17 | [Input("User")] 18 | [RequiredArgument] 19 | [ReferenceTarget("systemuser")] 20 | public InArgument User { get; set; } 21 | 22 | [Input("Read Access")] 23 | [RequiredArgument] 24 | [Default("False")] 25 | public InArgument ReadAccess { get; set; } 26 | 27 | [Input("Write Access")] 28 | [RequiredArgument] 29 | [Default("False")] 30 | public InArgument WriteAccess { get; set; } 31 | 32 | [Input("Delete Access")] 33 | [RequiredArgument] 34 | [Default("False")] 35 | public InArgument DeleteAccess { get; set; } 36 | 37 | [Input("Append Access")] 38 | [RequiredArgument] 39 | [Default("False")] 40 | public InArgument AppendAccess { get; set; } 41 | 42 | [Input("Append To Access")] 43 | [RequiredArgument] 44 | [Default("False")] 45 | public InArgument AppendToAccess { get; set; } 46 | 47 | [Input("Assign Access")] 48 | [RequiredArgument] 49 | [Default("False")] 50 | public InArgument AssignAccess { get; set; } 51 | 52 | [Input("Share Access")] 53 | [RequiredArgument] 54 | [Default("False")] 55 | public InArgument ShareAccess { get; set; } 56 | 57 | #endregion Input/Output Parameters 58 | 59 | protected override void ExecuteWorkflowLogic() 60 | { 61 | var target = ConvertToEntityReference(Record.Get(Context.ExecutionContext)); 62 | 63 | #region Build Sharing Mask 64 | 65 | var rights = AccessRights.None; 66 | 67 | if (ReadAccess.Get(Context.ExecutionContext)) 68 | { 69 | rights |= AccessRights.ReadAccess; 70 | } 71 | 72 | if (WriteAccess.Get(Context.ExecutionContext)) 73 | { 74 | rights |= AccessRights.WriteAccess; 75 | } 76 | 77 | if (DeleteAccess.Get(Context.ExecutionContext)) 78 | { 79 | rights |= AccessRights.DeleteAccess; 80 | } 81 | 82 | if (AppendAccess.Get(Context.ExecutionContext)) 83 | { 84 | rights |= AccessRights.AppendAccess ; 85 | } 86 | 87 | if (AppendToAccess.Get(Context.ExecutionContext)) 88 | { 89 | rights |= AccessRights.AppendToAccess; 90 | } 91 | 92 | if (AssignAccess.Get(Context.ExecutionContext)) 93 | { 94 | rights |= AccessRights.AssignAccess; 95 | } 96 | 97 | if (ShareAccess.Get(Context.ExecutionContext)) 98 | { 99 | rights |= AccessRights.ShareAccess; 100 | } 101 | 102 | #endregion Build Sharing Mask 103 | 104 | Context.SystemService.Execute(new ModifyAccessRequest() 105 | { 106 | PrincipalAccess = new PrincipalAccess() 107 | { 108 | AccessMask = rights, 109 | Principal = User.Get(Context.ExecutionContext) 110 | }, 111 | Target = target 112 | }); 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /CoreOperations/Security/ShareSecuredFieldsBase.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Activities; 3 | using Microsoft.Xrm.Sdk; 4 | using Microsoft.Xrm.Sdk.Query; 5 | using Microsoft.Xrm.Sdk.Messages; 6 | using Microsoft.Xrm.Sdk.Metadata; 7 | using Microsoft.Xrm.Sdk.Workflow; 8 | using UltimateWorkflowToolkit.Common; 9 | 10 | namespace UltimateWorkflowToolkit.CoreOperations.Security 11 | { 12 | public abstract class ShareSecuredFieldsBase : CrmWorkflowBase 13 | { 14 | #region Input/Output Parameters 15 | 16 | [Input("Record Reference")] 17 | [RequiredArgument] 18 | public InArgument Record { get; set; } 19 | 20 | [Input("Fields List (Comma Separated)")] 21 | [RequiredArgument] 22 | public InArgument Fields { get; set; } 23 | 24 | [Input("Read Access")] 25 | [RequiredArgument] 26 | [Default("False")] 27 | public InArgument ReadAccess { get; set; } 28 | 29 | [Input("Write Access")] 30 | [RequiredArgument] 31 | [Default("False")] 32 | public InArgument WriteAccess { get; set; } 33 | 34 | #endregion Input/Output Parameters 35 | 36 | public abstract EntityReference Principal { get; } 37 | 38 | protected override void ExecuteWorkflowLogic() 39 | { 40 | var target = ConvertToEntityReference(Record.Get(Context.ExecutionContext)); 41 | var principal = Principal; 42 | var readAccess = ReadAccess.Get(Context.ExecutionContext); 43 | var writeAccess = WriteAccess.Get(Context.ExecutionContext); 44 | 45 | //Let's retrieve attributes first 46 | var retrieveEntityRequest = new RetrieveEntityRequest() 47 | { 48 | LogicalName = target.LogicalName, 49 | EntityFilters = EntityFilters.Attributes, 50 | RetrieveAsIfPublished = true 51 | }; 52 | 53 | var retrieveEntityResponse = (RetrieveEntityResponse) Context.SystemService.Execute(retrieveEntityRequest); 54 | 55 | var fields = Fields.Get(Context.ExecutionContext).ToLowerInvariant().Split(',').ToArray(); 56 | 57 | foreach (var field in fields) 58 | { 59 | var crmAttribute = 60 | retrieveEntityResponse.EntityMetadata.Attributes.FirstOrDefault(a => a.LogicalName == field); 61 | 62 | if (crmAttribute?.IsSecured == null) 63 | throw new InvalidPluginExecutionException($"{field} attribute is not available in {target.LogicalName} entity"); 64 | 65 | if (!crmAttribute.IsSecured.Value) 66 | throw new InvalidPluginExecutionException($"{field} attribute is not secured"); 67 | 68 | var queryPOAA = new QueryByAttribute("principalobjectattributeaccess") 69 | { 70 | ColumnSet = new ColumnSet("readaccess", "updateaccess") 71 | }; 72 | queryPOAA.AddAttributeValue("attributeid", crmAttribute.MetadataId.Value); 73 | queryPOAA.AddAttributeValue("objectid", target.Id); 74 | queryPOAA.AddAttributeValue("principalid", principal.Id); 75 | 76 | var poaa = Context.SystemService.RetrieveMultiple(queryPOAA).Entities.FirstOrDefault(); 77 | 78 | if (poaa != null) 79 | { 80 | if (readAccess || writeAccess) 81 | { 82 | poaa["readaccess"] = readAccess; 83 | poaa["updateaccess"] = writeAccess; 84 | Context.SystemService.Update(poaa); 85 | } 86 | else 87 | Context.SystemService.Delete("principalobjectattributeaccess", poaa.Id); 88 | } 89 | else if (readAccess || writeAccess) 90 | { 91 | poaa = new Entity("principalobjectattributeaccess") 92 | { 93 | ["attributeid"] = crmAttribute.MetadataId.Value, 94 | ["objectid"] = target, 95 | ["readaccess"] = readAccess, 96 | ["updateaccess"] = writeAccess, 97 | ["principalid"] = principal 98 | }; 99 | 100 | Context.SystemService.Create(poaa); 101 | } 102 | } 103 | } 104 | } 105 | } -------------------------------------------------------------------------------- /CoreOperations/Security/ShareSecuredFieldsWithTeam.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | 5 | namespace UltimateWorkflowToolkit.CoreOperations.Security 6 | { 7 | public class ShareSecuredFieldsWithTeam : ShareSecuredFieldsBase 8 | { 9 | #region Input/Output Parameters 10 | 11 | [Input("Team")] 12 | [RequiredArgument] 13 | [ReferenceTarget("team")] 14 | public InArgument Team { get; set; } 15 | 16 | #endregion Input/Output Parameters 17 | 18 | public override EntityReference Principal 19 | { 20 | get 21 | { 22 | if (Context == null || Context.ExecutionContext == null) 23 | { 24 | return null; 25 | } 26 | 27 | return Team.Get(Context.ExecutionContext); 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /CoreOperations/Security/ShareSecuredFieldsWithUser.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | 5 | namespace UltimateWorkflowToolkit.CoreOperations.Security 6 | { 7 | public class ShareSecuredFieldsWithUser : ShareSecuredFieldsBase 8 | { 9 | #region Input/Output Parameters 10 | 11 | [Input("User")] 12 | [RequiredArgument] 13 | [ReferenceTarget("systemuser")] 14 | public InArgument User { get; set; } 15 | 16 | #endregion Input/Output Parameters 17 | 18 | public override EntityReference Principal 19 | { 20 | get 21 | { 22 | if (Context == null || Context.ExecutionContext == null) 23 | { 24 | return null; 25 | } 26 | 27 | return User.Get(Context.ExecutionContext); 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /CoreOperations/Security/UnshareRecordWithTeam.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using Microsoft.Crm.Sdk.Messages; 5 | using UltimateWorkflowToolkit.Common; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations.Security 8 | { 9 | public class UnshareRecordWithTeam : CrmWorkflowBase 10 | { 11 | #region Input/Output Parameters 12 | 13 | [Input("Record Reference")] 14 | [RequiredArgument] 15 | public InArgument Record { get; set; } 16 | 17 | [Input("Team")] 18 | [RequiredArgument] 19 | [ReferenceTarget("team")] 20 | public InArgument Team { get; set; } 21 | 22 | #endregion Input/Output Parameters 23 | 24 | protected override void ExecuteWorkflowLogic() 25 | { 26 | var target = ConvertToEntityReference(Record.Get(Context.ExecutionContext)); 27 | 28 | Context.SystemService.Execute(new RevokeAccessRequest() 29 | { 30 | Revokee = Team.Get(Context.ExecutionContext), 31 | Target = target 32 | }); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /CoreOperations/Security/UnshareRecordWithUser.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Workflow; 4 | using Microsoft.Crm.Sdk.Messages; 5 | using UltimateWorkflowToolkit.Common; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations.Security 8 | { 9 | public class UnshareRecordWithUser : CrmWorkflowBase 10 | { 11 | #region Input/Output Parameters 12 | 13 | [Input("Record Reference")] 14 | [RequiredArgument] 15 | public InArgument Record { get; set; } 16 | 17 | [Input("User")] 18 | [RequiredArgument] 19 | [ReferenceTarget("systemuser")] 20 | public InArgument User { get; set; } 21 | 22 | #endregion Input/Output Parameters 23 | 24 | protected override void ExecuteWorkflowLogic() 25 | { 26 | var target = ConvertToEntityReference(Record.Get(Context.ExecutionContext)); 27 | 28 | Context.SystemService.Execute(new RevokeAccessRequest() 29 | { 30 | Revokee = User.Get(Context.ExecutionContext), 31 | Target = target 32 | }); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /CoreOperations/StringRoutines/StringJoin.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Activities; 3 | using System.Reflection; 4 | using System.Collections.Generic; 5 | using Microsoft.Xrm.Sdk.Workflow; 6 | using UltimateWorkflowToolkit.Common; 7 | 8 | namespace UltimateWorkflowToolkit.CoreOperations.StringRoutines 9 | { 10 | public class StringJoin: CrmWorkflowBase 11 | { 12 | #region Workflow Arguments 13 | 14 | [Input("In 1")] 15 | public InArgument In1 { get; set; } 16 | 17 | [Input("In 2")] 18 | public InArgument In2 { get; set; } 19 | 20 | [Input("In 3")] 21 | public InArgument In3 { get; set; } 22 | 23 | [Input("In 4")] 24 | public InArgument In4 { get; set; } 25 | 26 | [Input("In 5")] 27 | public InArgument In5 { get; set; } 28 | 29 | [Input("In 6")] 30 | public InArgument In6 { get; set; } 31 | 32 | [Input("In 7")] 33 | public InArgument In7 { get; set; } 34 | 35 | [Input("In 8")] 36 | public InArgument In8 { get; set; } 37 | 38 | [Input("In 9")] 39 | public InArgument In9 { get; set; } 40 | 41 | [Input("In 10")] 42 | public InArgument In10 { get; set; } 43 | 44 | [Input("Separator")] 45 | public InArgument Separator { get; set; } 46 | 47 | [Output("Result")] 48 | public OutArgument Result { get; set; } 49 | 50 | #endregion 51 | 52 | protected override void ExecuteWorkflowLogic() 53 | { 54 | var allStrings = new List(); 55 | 56 | var properties = GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); 57 | 58 | properties.ToList().ForEach(p => 59 | { 60 | if (p.PropertyType.IsSubclassOf(typeof(InArgument)) && 61 | p.Name.StartsWith("In")) 62 | { 63 | var property = (Argument)p.GetValue(this); 64 | var propertyValue = property.Get(Context.ExecutionContext); 65 | 66 | if (propertyValue != null) 67 | { 68 | allStrings.Add((string)propertyValue); 69 | } 70 | } 71 | }); 72 | 73 | var separator = Separator.Get(Context.ExecutionContext) ?? string.Empty; 74 | 75 | var result = string.Join(separator, allStrings); 76 | 77 | Result.Set(Context.ExecutionContext, result); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /CoreOperations/System/CancelOtherInstances.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using Microsoft.Xrm.Sdk; 3 | using Microsoft.Xrm.Sdk.Query; 4 | using UltimateWorkflowToolkit.Common; 5 | 6 | namespace UltimateWorkflowToolkit.CoreOperations.System 7 | { 8 | public class CancelOtherInstances : CrmWorkflowBase 9 | { 10 | protected override void ExecuteWorkflowLogic() 11 | { 12 | Entity asyncOperation = Context.SystemService.Retrieve("asyncoperation", Context.WorkflowExecutionContext.OperationId, new ColumnSet("workflowactivationid")); 13 | 14 | var asyncOperationsQuery = new QueryExpression("asyncoperation") 15 | { 16 | ColumnSet = new ColumnSet(false) 17 | }; 18 | asyncOperationsQuery.Criteria.AddCondition("asyncoperationid", ConditionOperator.NotEqual, asyncOperation.Id); 19 | asyncOperationsQuery.Criteria.AddCondition("workflowactivationid", ConditionOperator.Equal, 20 | asyncOperation.GetAttributeValue("workflowactivationid").Id); 21 | asyncOperationsQuery.Criteria.AddCondition("statecode", ConditionOperator.Equal, 1); 22 | asyncOperationsQuery.Criteria.AddCondition("regardingobjectid", ConditionOperator.Equal, Context.WorkflowExecutionContext.PrimaryEntityId); 23 | 24 | var existingInstances = Context.SystemService.RetrieveMultiple(asyncOperationsQuery).Entities.ToList(); 25 | 26 | 27 | foreach (Entity existingInstance in existingInstances) 28 | { 29 | existingInstance["statecode"] = new OptionSetValue(3); 30 | existingInstance["statuscode"] = new OptionSetValue(32); 31 | 32 | Context.SystemService.Update(existingInstance); 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /CoreOperations/System/RecalculateAllRollups.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Activities; 3 | using Microsoft.Crm.Sdk.Messages; 4 | using Microsoft.Xrm.Sdk.Messages; 5 | using Microsoft.Xrm.Sdk.Metadata; 6 | using Microsoft.Xrm.Sdk.Workflow; 7 | using UltimateWorkflowToolkit.Common; 8 | 9 | namespace UltimateWorkflowToolkit.CoreOperations.System 10 | { 11 | public class RecalculateAllRollups : CrmWorkflowBase 12 | { 13 | #region Input/Output Arguments 14 | 15 | [Input("Record Reference")] 16 | [RequiredArgument] 17 | public InArgument Record { get; set; } 18 | 19 | #endregion Input/Output Arguments 20 | 21 | protected override void ExecuteWorkflowLogic() 22 | { 23 | var target = ConvertToEntityReference(Record.Get(Context.ExecutionContext)); 24 | 25 | var retrieveEntityResponse = (RetrieveEntityResponse)Context.SystemService.Execute(new RetrieveEntityRequest() 26 | { 27 | EntityFilters = EntityFilters.Attributes, 28 | LogicalName = target.LogicalName, 29 | RetrieveAsIfPublished = true 30 | }); 31 | 32 | var entityMetadata = retrieveEntityResponse.EntityMetadata; 33 | 34 | entityMetadata.Attributes.Where(a => a.SourceType == 2 && (a.GetType() != typeof(MoneyAttributeMetadata) || (a is MoneyAttributeMetadata && ((MoneyAttributeMetadata)a).CalculationOf == null))).Select(a => a.LogicalName).ToList().ForEach(fieldName => { 35 | Context.SystemService.Execute(new CalculateRollupFieldRequest() 36 | { 37 | FieldName = fieldName, 38 | Target = target 39 | }); 40 | }); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /CoreOperations/System/RecalculateRollup.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk.Workflow; 3 | using Microsoft.Crm.Sdk.Messages; 4 | using UltimateWorkflowToolkit.Common; 5 | 6 | namespace UltimateWorkflowToolkit.CoreOperations.System 7 | { 8 | public class RecalculateRollup : CrmWorkflowBase 9 | { 10 | #region Input/Output Arguments 11 | 12 | [Input("Record Reference")] 13 | [RequiredArgument] 14 | public InArgument Record { get; set; } 15 | 16 | [Input("Rollup Field Name")] 17 | [RequiredArgument] 18 | public InArgument FieldName { get; set; } 19 | 20 | #endregion Input/Output Arguments 21 | 22 | protected override void ExecuteWorkflowLogic() 23 | { 24 | var target = ConvertToEntityReference(Record.Get(Context.ExecutionContext)); 25 | 26 | Context.SystemService.Execute(new CalculateRollupFieldRequest() 27 | { 28 | FieldName = FieldName.Get(Context.ExecutionContext), 29 | Target = target 30 | }); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /CoreOperations/System/RefreshCurrencyExchangeRates.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | using System.IO; 3 | using System.Linq; 4 | using System.Collections.Generic; 5 | using Newtonsoft.Json.Linq; 6 | using Microsoft.Xrm.Sdk; 7 | using Microsoft.Xrm.Sdk.Query; 8 | using UltimateWorkflowToolkit.Common; 9 | 10 | namespace UltimateWorkflowToolkit.CoreOperations.System 11 | { 12 | public class RefreshCurrencyExchangeRates : CrmWorkflowBase 13 | { 14 | protected override void ExecuteWorkflowLogic() 15 | { 16 | #region Get All Currencies From Endpoint and check that call was successfull 17 | 18 | string jsonResult = null; 19 | 20 | var url = "http://apilayer.net/api/live?access_key=" + Context.Settings.CurrencylayerKey; 21 | var request = (HttpWebRequest)WebRequest.Create(url); 22 | using (var resStream = new StreamReader(request.GetResponse().GetResponseStream())) 23 | { 24 | jsonResult = resStream.ReadToEnd(); 25 | } 26 | 27 | var jobject = JObject.Parse(jsonResult); 28 | 29 | var success = jobject.SelectToken("$.success").Value(); 30 | 31 | if (!success) 32 | { 33 | var errorToken = jobject.SelectToken("$.error"); 34 | var errorMessage = $@"Can't obtain currency exchange rates: 35 | Code: {errorToken.SelectToken("code").Value()} 36 | Type: {errorToken.SelectToken("type").Value()} 37 | Info: {errorToken.SelectToken("info").Value()}"; 38 | 39 | throw new InvalidPluginExecutionException(errorMessage); 40 | } 41 | 42 | #endregion Get All Currencies From Endpoint and check that call was successfull 43 | 44 | #region Get Base Currency 45 | 46 | QueryExpression query = new QueryExpression("transactioncurrency") 47 | { 48 | ColumnSet = new ColumnSet("isocurrencycode", "currencyname") 49 | }; 50 | query.AddLink("organization", "transactioncurrencyid", "basecurrencyid", JoinOperator.Inner); 51 | 52 | var baseCurrency = Context.SystemService.RetrieveMultiple(query).Entities.FirstOrDefault(); 53 | 54 | if (baseCurrency == null) 55 | return; 56 | 57 | var baseCurrencyCode = baseCurrency.GetAttributeValue("isocurrencycode").ToUpper(); 58 | var baseCurrencyId = baseCurrency.Id; 59 | var baseCurrencyName = baseCurrency.GetAttributeValue("currencyname"); 60 | 61 | var baseCurrencyNode = jobject.SelectToken($"$.quotes.USD{baseCurrencyCode}"); 62 | 63 | if (baseCurrencyNode == null) 64 | { 65 | throw new InvalidPluginExecutionException($"Exchange Rates for your Base Currency ({baseCurrencyName}) are not available"); 66 | } 67 | 68 | var usdToBaseCurrencyRate = baseCurrencyNode.Value(); 69 | 70 | #endregion Get Base Currency 71 | 72 | #region Getting All Currencies Except Base Currency 73 | 74 | query = new QueryExpression("transactioncurrency") 75 | { 76 | ColumnSet = new ColumnSet("isocurrencycode", "currencyname") 77 | }; 78 | query.Criteria.AddCondition("transactioncurrencyid", ConditionOperator.NotEqual, baseCurrencyId); 79 | 80 | List allCurrencies = Context.SystemService.RetrieveMultiple(query).Entities.ToList(); 81 | 82 | #endregion Getting All Currencies Except Base Currency 83 | 84 | #region Looping through currencies and updating Exhange Rates 85 | 86 | foreach (Entity currency in allCurrencies) 87 | { 88 | var currencyCode = currency.GetAttributeValue("isocurrencycode").ToUpper(); 89 | var currencyName = currency.GetAttributeValue("currencyname"); 90 | 91 | var currencyNode = jobject.SelectToken($"$.quotes.USD{currencyCode}"); 92 | 93 | if (currencyNode == null) 94 | { 95 | Context.TracingService.Trace($"Can't refresh exchange rate for {currencyName} currency"); 96 | continue; 97 | } 98 | 99 | var usdToCurrencyRate = currencyNode.Value(); 100 | 101 | 102 | decimal rate = usdToCurrencyRate / usdToBaseCurrencyRate; 103 | 104 | currency.Attributes.Clear(); 105 | currency["exchangerate"] = rate; 106 | 107 | Context.SystemService.Update(currency); 108 | } 109 | 110 | #endregion Looping through currencies and updating Exhange Rates 111 | } 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /CoreOperations/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Andrii Butenko 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MultiselectHelper/AddValuesToField.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Collections.Generic; 3 | using Microsoft.Xrm.Sdk; 4 | 5 | namespace UltimateWorkflowToolkit.MultiselectHelper 6 | { 7 | public class AddValuesToField : FieldOperationBase 8 | { 9 | protected override void ExecuteWorkflowLogic() 10 | { 11 | if (string.IsNullOrEmpty(Values)) 12 | throw new InvalidPluginExecutionException("Values parameter is empty"); 13 | 14 | var intValues = ConvertStringToIntArray(Values); 15 | 16 | var currentFieldValue = Record.GetAttributeValue(FieldName)?.ToList(); 17 | 18 | if (currentFieldValue == null) 19 | currentFieldValue = new List(); 20 | 21 | foreach (var intValue in intValues) 22 | { 23 | var existingOption = currentFieldValue.FirstOrDefault(o => o.Value == intValue); 24 | if (existingOption != null) 25 | continue; 26 | 27 | currentFieldValue.Add(new OptionSetValue(intValue)); 28 | } 29 | 30 | var record = Record; 31 | record[FieldName] = new OptionSetValueCollection(currentFieldValue); 32 | 33 | Context.UserService.Update(record); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /MultiselectHelper/FieldContainsAllValues.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Activities; 3 | using Microsoft.Xrm.Sdk; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | 6 | namespace UltimateWorkflowToolkit.MultiselectHelper 7 | { 8 | public class FieldContainsAllValues : FieldOperationBase 9 | { 10 | #region Input/Output Parameters 11 | 12 | [Output("Field Contains One of Values")] 13 | public OutArgument IsFieldContainAllValues { get; set; } 14 | 15 | #endregion Input/Output Parameters 16 | 17 | protected override void ExecuteWorkflowLogic() 18 | { 19 | if (!Record.Contains(FieldName)) 20 | { 21 | IsFieldContainAllValues.Set(Context.ExecutionContext, false); 22 | return; 23 | } 24 | 25 | if (string.IsNullOrEmpty(Values)) 26 | throw new InvalidPluginExecutionException("Values parameter is empty"); 27 | 28 | var intValues = ConvertStringToIntArray(Values); 29 | 30 | var currentFieldValue = Record.GetAttributeValue(FieldName).Select(o => o.Value).ToList(); 31 | 32 | var result = true; 33 | 34 | foreach (var intValue in intValues) 35 | { 36 | if (!currentFieldValue.Contains(intValue)) 37 | { 38 | result = false; 39 | break; 40 | } 41 | } 42 | 43 | IsFieldContainAllValues.Set(Context.ExecutionContext, result); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /MultiselectHelper/FieldContainsData.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk.Workflow; 3 | 4 | namespace UltimateWorkflowToolkit.MultiselectHelper 5 | { 6 | public class FieldContainsData: MultiselectWorkflowBase 7 | { 8 | 9 | #region Input/Output Parameters 10 | 11 | [Output("Field Contains Value")] 12 | public OutArgument IsFieldContainsData { get; set; } 13 | 14 | #endregion 15 | 16 | protected override void ExecuteWorkflowLogic() 17 | { 18 | IsFieldContainsData.Set(Context.ExecutionContext, Record.Contains(FieldName)); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /MultiselectHelper/FieldContainsOneOfValues.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using System.Collections.Generic; 3 | using Microsoft.Xrm.Sdk; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | 6 | namespace UltimateWorkflowToolkit.MultiselectHelper 7 | { 8 | public class FieldContainsOneOfValues : FieldOperationBase 9 | { 10 | #region Input/Output Parameters 11 | 12 | [Output("Field Contains One of Values")] 13 | public OutArgument IsFieldContainOneofValues { get; set; } 14 | 15 | #endregion Input/Output Parameters 16 | 17 | protected override void ExecuteWorkflowLogic() 18 | { 19 | if (string.IsNullOrEmpty(Values)) 20 | throw new InvalidPluginExecutionException("Values parameter is empty"); 21 | 22 | List intValues = ConvertStringToIntArray(Values); 23 | 24 | if (!Record.Contains(FieldName)) 25 | { 26 | IsFieldContainOneofValues.Set(Context.ExecutionContext, false); 27 | return; 28 | } 29 | 30 | var currentFieldValue = Record.GetAttributeValue(FieldName); 31 | 32 | var result = false; 33 | 34 | foreach (var picklistValue in currentFieldValue) 35 | { 36 | if (intValues.Contains(picklistValue.Value)) 37 | { 38 | result = true; 39 | break; 40 | } 41 | } 42 | 43 | IsFieldContainOneofValues.Set(Context.ExecutionContext, result); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /MultiselectHelper/FieldEqualsTo.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Activities; 3 | using Microsoft.Xrm.Sdk; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | 6 | namespace UltimateWorkflowToolkit.MultiselectHelper 7 | { 8 | public class FieldEqualsTo : FieldOperationBase 9 | { 10 | 11 | #region Input/Output Parameters 12 | 13 | [Output("Field Equals to Value")] 14 | public OutArgument IsFieldEquals { get; set; } 15 | 16 | #endregion Input/Output Parameters 17 | 18 | protected override void ExecuteWorkflowLogic() 19 | { 20 | if (string.IsNullOrEmpty(Values) && !Record.Contains(FieldName)) 21 | IsFieldEquals.Set(Context.ExecutionContext, true); 22 | else if ((string.IsNullOrEmpty(Values) && Record.Contains(FieldName)) || 23 | !string.IsNullOrEmpty(Values) && !Record.Contains(FieldName)) 24 | IsFieldEquals.Set(Context.ExecutionContext, false); 25 | else 26 | { 27 | var intValues = ConvertStringToIntArray(Values); 28 | var crmValues = Record.GetAttributeValue(FieldName).Select(o => o.Value).ToList(); 29 | 30 | foreach (var intValue in intValues) 31 | { 32 | if (!crmValues.Contains(intValue)) 33 | { 34 | IsFieldEquals.Set(Context.ExecutionContext, false); 35 | return; 36 | } 37 | } 38 | 39 | IsFieldEquals.Set(Context.ExecutionContext, true); 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /MultiselectHelper/FieldOperationBase.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk.Workflow; 3 | 4 | namespace UltimateWorkflowToolkit.MultiselectHelper 5 | { 6 | public abstract class FieldOperationBase : MultiselectWorkflowBase 7 | { 8 | #region Input/Output Parameters 9 | 10 | [Input("Values")] 11 | [RequiredArgument] 12 | public InArgument ValuesString { get; set; } 13 | 14 | protected string Values 15 | { 16 | get 17 | { 18 | if (Context == null || Context.ExecutionContext == null) 19 | return null; 20 | 21 | return ValuesString.Get(Context.ExecutionContext); 22 | } 23 | } 24 | 25 | #endregion Input/Output Parameters 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /MultiselectHelper/GetFieldLabel.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using Microsoft.Xrm.Sdk.Workflow; 3 | 4 | namespace UltimateWorkflowToolkit.MultiselectHelper 5 | { 6 | public class GetFieldLabel : MultiselectWorkflowBase 7 | { 8 | #region Input/Output Parameters 9 | 10 | [Output("Field Label")] 11 | public OutArgument FieldLabel { get; set; } 12 | 13 | #endregion 14 | protected override void ExecuteWorkflowLogic() 15 | { 16 | var record = Record; 17 | 18 | var result = string.Empty; 19 | 20 | if (record.Contains(FieldName)) 21 | result = record.FormattedValues[FieldName]; 22 | 23 | FieldLabel.Set(Context.ExecutionContext, result); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /MultiselectHelper/Key.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewButenko/UltimateWorkflowToolkit/ccb19d7efc70ddaf54d4ff99371b944f50df131b/MultiselectHelper/Key.snk -------------------------------------------------------------------------------- /MultiselectHelper/MultiselectWorkflowBase.cs: -------------------------------------------------------------------------------- 1 | using System.Activities; 2 | using System.Collections.Generic; 3 | using Microsoft.Xrm.Sdk; 4 | using Microsoft.Xrm.Sdk.Query; 5 | using Microsoft.Xrm.Sdk.Workflow; 6 | using UltimateWorkflowToolkit.Common; 7 | 8 | namespace UltimateWorkflowToolkit.MultiselectHelper 9 | { 10 | public abstract class MultiselectWorkflowBase : CrmWorkflowBase 11 | { 12 | 13 | #region Input/Output Parameters 14 | 15 | [Input("Record Reference")] 16 | [RequiredArgument] 17 | public InArgument RecordReferenceString { get; set; } 18 | 19 | [Input("Field Name")] 20 | [RequiredArgument] 21 | public InArgument FieldNameString { get; set; } 22 | 23 | #endregion Input/Output Parameters 24 | 25 | #region Protected Members 26 | 27 | protected Entity Record 28 | { 29 | get 30 | { 31 | if (Context?.ExecutionContext == null) 32 | return null; 33 | 34 | var recordReference = ConvertToEntityReference(RecordReferenceString.Get(Context.ExecutionContext)); 35 | 36 | return Context.UserService.Retrieve(recordReference.LogicalName, recordReference.Id, new ColumnSet(FieldName)); 37 | } 38 | } 39 | 40 | protected string FieldName 41 | { 42 | get 43 | { 44 | return Context?.ExecutionContext == null ? null : FieldNameString.Get(Context.ExecutionContext); 45 | } 46 | } 47 | 48 | protected List ConvertStringToIntArray(string stringValues) 49 | { 50 | if (string.IsNullOrEmpty(stringValues)) 51 | throw new InvalidPluginExecutionException("Parameter StringValues can't be empty!"); 52 | 53 | var intValues = new List(); 54 | 55 | var stringValuesList = stringValues.Replace(" ", string.Empty).Split('|'); 56 | 57 | foreach (var stringValue in stringValuesList) 58 | { 59 | int parseResult; 60 | 61 | if (!int.TryParse(stringValue, out parseResult)) 62 | { 63 | throw new InvalidPluginExecutionException($"{stringValue} can't be parsed as valid whole number"); 64 | } 65 | 66 | intValues.Add(parseResult); 67 | } 68 | 69 | return intValues; 70 | } 71 | 72 | #endregion Protected Members 73 | 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /MultiselectHelper/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("UltimateWorkflowToolkit.MultiselectHelper")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("UltimateWorkflowToolkit.MultiselectHelper")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("2e826f55-b945-4c41-ade0-ef8d4d3846ac")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /MultiselectHelper/RemoveValuesFromField.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Collections.Generic; 3 | using Microsoft.Xrm.Sdk; 4 | 5 | namespace UltimateWorkflowToolkit.MultiselectHelper 6 | { 7 | public class RemoveValuesFromField : FieldOperationBase 8 | { 9 | protected override void ExecuteWorkflowLogic() 10 | { 11 | if (string.IsNullOrEmpty(Values)) 12 | throw new InvalidPluginExecutionException("Values parameter is empty"); 13 | 14 | var intValues = ConvertStringToIntArray(Values); 15 | 16 | var currentFieldValue = Record.GetAttributeValue(FieldName)?.ToList(); 17 | 18 | if (currentFieldValue == null) 19 | currentFieldValue = new List(); 20 | 21 | foreach (var intValue in intValues) 22 | { 23 | var existingOption = currentFieldValue.FirstOrDefault(o => o.Value == intValue); 24 | if (existingOption == null) 25 | continue; 26 | 27 | currentFieldValue.Remove(existingOption); 28 | } 29 | 30 | var record = Record; 31 | record[FieldName] = new OptionSetValueCollection(currentFieldValue); 32 | 33 | Context.UserService.Update(record); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /MultiselectHelper/SetFieldValue.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using Microsoft.Xrm.Sdk; 3 | 4 | namespace UltimateWorkflowToolkit.MultiselectHelper 5 | { 6 | public class SetFieldValue : FieldOperationBase 7 | { 8 | protected override void ExecuteWorkflowLogic() 9 | { 10 | if (string.IsNullOrEmpty(Values)) 11 | throw new InvalidPluginExecutionException("Values parameter is empty"); 12 | 13 | var intValues = ConvertStringToIntArray(Values).Select(o => new OptionSetValue(o)).ToList(); 14 | 15 | var record = Record; 16 | 17 | record[FieldName] = new OptionSetValueCollection(intValues); 18 | 19 | Context.UserService.Update(record); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /MultiselectHelper/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /UltimateWorkflowToolkit.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CoreOperations", "CoreOperations\CoreOperations.csproj", "{2110F684-C277-47E7-B8B9-6F17A579D0CE}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "Common\Common.csproj", "{BE47DB29-FC51-4450-B2C2-98AFA33DDFFF}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MultiselectHelper", "MultiselectHelper\MultiselectHelper.csproj", "{2E826F55-B945-4C41-ADE0-EF8D4D3846AC}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebResources", "WebResources\WebResources.csproj", "{050FD5D5-B885-47AE-8CF5-27D980DFA4BC}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Release|Any CPU = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {2110F684-C277-47E7-B8B9-6F17A579D0CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {2110F684-C277-47E7-B8B9-6F17A579D0CE}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {2110F684-C277-47E7-B8B9-6F17A579D0CE}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {2110F684-C277-47E7-B8B9-6F17A579D0CE}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {BE47DB29-FC51-4450-B2C2-98AFA33DDFFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {BE47DB29-FC51-4450-B2C2-98AFA33DDFFF}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {BE47DB29-FC51-4450-B2C2-98AFA33DDFFF}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {BE47DB29-FC51-4450-B2C2-98AFA33DDFFF}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {2E826F55-B945-4C41-ADE0-EF8D4D3846AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {2E826F55-B945-4C41-ADE0-EF8D4D3846AC}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {2E826F55-B945-4C41-ADE0-EF8D4D3846AC}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {2E826F55-B945-4C41-ADE0-EF8D4D3846AC}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {050FD5D5-B885-47AE-8CF5-27D980DFA4BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {050FD5D5-B885-47AE-8CF5-27D980DFA4BC}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {050FD5D5-B885-47AE-8CF5-27D980DFA4BC}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {050FD5D5-B885-47AE-8CF5-27D980DFA4BC}.Release|Any CPU.Build.0 = Release|Any CPU 36 | EndGlobalSection 37 | GlobalSection(SolutionProperties) = preSolution 38 | HideSolutionNode = FALSE 39 | EndGlobalSection 40 | EndGlobal 41 | -------------------------------------------------------------------------------- /WebResources/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("WebResources")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("WebResources")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("050fd5d5-b885-47ae-8cf5-27d980dfa4bc")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /WebResources/WebResources.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Debug 7 | AnyCPU 8 | 9 | 10 | 2.0 11 | {050FD5D5-B885-47AE-8CF5-27D980DFA4BC} 12 | {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} 13 | Library 14 | Properties 15 | WebResources 16 | WebResources 17 | v4.5.2 18 | true 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 1.8 27 | 28 | 29 | true 30 | full 31 | false 32 | bin\ 33 | DEBUG;TRACE 34 | prompt 35 | 4 36 | 37 | 38 | pdbonly 39 | true 40 | bin\ 41 | TRACE 42 | prompt 43 | 4 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 10.0 64 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | True 75 | True 76 | 23634 77 | / 78 | http://localhost:23634/ 79 | False 80 | False 81 | 82 | 83 | False 84 | 85 | 86 | 87 | 88 | 95 | -------------------------------------------------------------------------------- /WebResources/uwt_/Settings.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 16 | 17 | 18 |
19 |
20 | 21 | 22 | Visit BingMaps Portal to obtain a valid key 23 |
24 |
25 | 26 | 27 | Visit Cloudconvert Portal to obtain a valid key 28 |
29 |
30 | 31 | 32 | Visit Currencylayer Portal to obtain a valid key 33 |
34 |
35 | 36 | 37 | This is base Url of Dynamics 365 38 |
39 | 40 |
41 | 42 | -------------------------------------------------------------------------------- /WebResources/uwt_/Settings.js: -------------------------------------------------------------------------------- 1 | var Settings = (function () { 2 | 3 | var settingid = null; 4 | var settingsobject = {}; 5 | 6 | function onLoad() { 7 | var req = new XMLHttpRequest(); 8 | req.open("GET", GetGlobalContext().getClientUrl() + "/api/data/v8.0/uwt_settingses?$select=uwt_settingsid,uwt_settingsstring", true); 9 | req.setRequestHeader("OData-MaxVersion", "4.0"); 10 | req.setRequestHeader("OData-Version", "4.0"); 11 | req.setRequestHeader("Accept", "application/json"); 12 | req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); 13 | req.setRequestHeader("Prefer", "odata.include-annotations=\"*\",odata.maxpagesize=1"); 14 | req.onreadystatechange = function () { 15 | if (this.readyState === 4) { 16 | req.onreadystatechange = null; 17 | if (this.status === 200) { 18 | var results = JSON.parse(this.response); 19 | 20 | if (results.value.length !== 0) { 21 | settingid = results.value[0].uwt_settingsid; 22 | var settingsstring = results.value[0]["uwt_settingsstring"]; 23 | settingsobject = JSON.parse(settingsstring); 24 | } 25 | 26 | if (typeof settingsobject.BingMapsKey !== "undefined") 27 | $("#teBingMapsKey").val(settingsobject.BingMapsKey); 28 | 29 | if (typeof settingsobject.CloudConvertKey !== "undefined") 30 | $("#teCloudConvertKey").val(settingsobject.CloudConvertKey); 31 | 32 | if (typeof settingsobject.CurrencylayerKey !== "undefined") 33 | $("#teCurrencylayerKey").val(settingsobject.CurrencylayerKey); 34 | 35 | if (typeof settingsobject.BaseUrl === "undefined") { 36 | settingsobject.BaseUrl = GetGlobalContext().getClientUrl(); 37 | } 38 | 39 | $("#teBaseUrl").val(settingsobject.BaseUrl); 40 | } 41 | } 42 | }; 43 | req.send(); 44 | } 45 | 46 | function onSave() { 47 | settingsobject = {}; 48 | 49 | if ($("#teBingMapsKey").val() != null) { 50 | settingsobject.BingMapsKey = $("#teBingMapsKey").val(); 51 | } 52 | 53 | if ($("#teCloudConvertKey").val() != null) { 54 | settingsobject.CloudConvertKey = $("#teCloudConvertKey").val(); 55 | } 56 | 57 | if ($("#teCurrencylayerKey").val() != null) { 58 | settingsobject.CurrencylayerKey = $("#teCurrencylayerKey").val(); 59 | } 60 | 61 | if ($("#teBaseUrl").val() != null) { 62 | settingsobject.BaseUrl = $("#teBaseUrl").val(); 63 | } 64 | 65 | var settingsRecord = { 66 | uwt_settingsstring: JSON.stringify(settingsobject) 67 | }; 68 | 69 | var req = new XMLHttpRequest(); 70 | 71 | if (settingid == null) 72 | req.open("POST", GetGlobalContext().getClientUrl() + "/api/data/v8.0/uwt_settingses", true); 73 | else 74 | req.open("PATCH", GetGlobalContext().getClientUrl() + "/api/data/v8.0/uwt_settingses(" + settingid + ")", true); 75 | 76 | req.setRequestHeader("OData-MaxVersion", "4.0"); 77 | req.setRequestHeader("OData-Version", "4.0"); 78 | req.setRequestHeader("Accept", "application/json"); 79 | req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); 80 | req.onreadystatechange = function () { 81 | if (this.readyState === 4) { 82 | req.onreadystatechange = null; 83 | if (this.status === 204) { 84 | if (settingid == null) { 85 | var uri = this.getResponseHeader("OData-EntityId"); 86 | var regExp = /\(([^)]+)\)/; 87 | var matches = regExp.exec(uri); 88 | settingid = matches[1]; 89 | } 90 | } else { 91 | Xrm.Utility.alertDialog(this.statusText); 92 | } 93 | } 94 | }; 95 | req.send(JSON.stringify(settingsRecord)); 96 | } 97 | 98 | return { 99 | OnLoad: onLoad, 100 | OnSave: onSave 101 | }; 102 | })(); -------------------------------------------------------------------------------- /Workflows/CaseClose.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Activities; 3 | using Microsoft.Xrm.Sdk; 4 | using Microsoft.Xrm.Sdk.Workflow; 5 | using Microsoft.Crm.Sdk.Messages; 6 | 7 | namespace UltimateWorkflowToolkit.CoreOperations 8 | { 9 | public class CaseClose : CrmWorkflowBase 10 | { 11 | #region Input/Output Parameters 12 | 13 | [Input("Case")] 14 | [ReferenceTarget("incident")] 15 | [RequiredArgument] 16 | public InArgument Incident { get; set; } 17 | 18 | [Input("Case Status")] 19 | [AttributeTarget("incident", "statuscode")] 20 | [RequiredArgument] 21 | public InArgument IncidentStatus { get; set; } 22 | 23 | [Input("Case Close: Subject")] 24 | public InArgument Subject { get; set; } 25 | 26 | [Input("Case Close: Close Date")] 27 | [RequiredArgument] 28 | public InArgument CloseDate { get; set; } 29 | 30 | [Input("Case Close: Description")] 31 | public InArgument Description { get; set; } 32 | 33 | #endregion Input/Output Parameters 34 | 35 | protected override void ExecuteWorkflowLogic(CodeActivityContext executionContext, IWorkflowContext context, IOrganizationService service) 36 | { 37 | var incidentCloseRequest = new CloseIncidentRequest() 38 | { 39 | Status = IncidentStatus.Get(executionContext), 40 | IncidentResolution = new Entity("incidentresolution") 41 | { 42 | ["subject"] = Subject.Get(executionContext), 43 | ["incidentid"] = Incident.Get(executionContext), 44 | ["actualend"] = CloseDate.Get(executionContext), 45 | ["description"] = Description.Get(executionContext) 46 | } 47 | }; 48 | 49 | service.Execute(incidentCloseRequest); 50 | } 51 | } 52 | } 53 | --------------------------------------------------------------------------------