Define different types of Input and Output arguments for custom workflow activity

As a MS Dynamics CRM Developer there are certain situations where you need to pass some of the entity field values as Input arguments to a Custom Workflow activity and some cases you may require to get some of the code execution results as Output arguments from a custom workflow activity.

In order to accomplish this you definitely need to have an idea on the Syntax of the Input and Output arguments for different types of fields.

Here i considered an entity called Patient which is having different types of fields and those are given below
1. Patient Name : String
2. Date Of Birth : Date and Time
3. Hospital : Lookup (to an entity called Hospital)
4. Patient Status : Option Set
5. Hospitalization Required : Two Option Set
6. Patient Age : Whole Number
7. Consultation Fee : Decimal Number
8. Estimated Amount : Floating Point Number
9. Treatment Cost : Currency
10. Patient Id : String

Types of arguments

  1. Input : Entity field value can be passed to Custom workflow activity
  2. Output : Execution result (if any) can be passed as output from Custom workflow activity
  3. Input/Output : It can be used as both Input and Output

The following Custom Workflow Activity code will explains how to declare Input and Output arguments.

using System;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Workflow;
using System.Activities;

namespace InputOutputParameters
    public class InputOutputParameters : CodeActivity
        //Data Type : String 
        public InArgument<string> PatientName { get; set; }

        //Data Type : Date and Time
        public InArgument DateOfBirth { get; set; }

        //Data Type : Lookup
        public InArgument Hospital { get; set; }

        //Data Type : Option Set
        [AttributeTarget("new_patient", "statuscode")]
        public InArgument PatientStatus { get; set; }

        //Data Type : Two Option Set
        public InArgument<bool> HospitalizationRequired { get; set; }

        //Data Type : Whole Number
        public InArgument<int> PatientAge { get; set; }

        //Data Type : Decimal Number
        public InArgument<decimal> ConsultationFee { get; set; }

        //Data Type : Floating Point Number
        public InArgument<decimal> EstimatedAmount { get; set; }

        //Data Type : Currency
        public InArgument TreatmentCost { get; set; }

        //Data Type : String
        public OutArgument<string> ShowPatientDetails { get; set; }

        //Data Type : String (Can be used as Input/Output)
        public InOutArgument<string> PatientInOut { get; set; }

        protected override void Execute(CodeActivityContext context)
                IWorkflowContext workflowContext = context.GetExtension();
                IOrganizationServiceFactory serviceFactory = context.GetExtension();
                IOrganizationService service = serviceFactory.CreateOrganizationService(workflowContext.UserId);
                ITracingService tracingService = context.GetExtension();

                tracingService.Trace("Patient Details using input and output parameters Workflow Started.");
                var patientName = PatientName.Get(context);
                var dateOfBirth = DateOfBirth.Get(context);
                var hospital = Hospital.Get(context)?.Name;
                var patientStatus = PatientStatus.Get(context).Value;
                var hospitalizationRequired = HospitalizationRequired.Get(context);
                var patientAge = PatientAge.Get(context);
                var consultationFee = ConsultationFee.Get(context);
                var estimatedAmount = EstimatedAmount.Get(context);
                var treatmentCost = TreatmentCost.Get(context).Value;
                var patientId = PatientInOut.Get(context);
                tracingService.Trace($"Patient Name : {patientName}, Date Of Birth : {dateOfBirth}, Hospital : {hospital}, Patient Status : {patientStatus}, Hospitalization Required: {hospitalizationRequired}, Patient Age: {patientAge}, Consultation Fee : {consultationFee}, Estimated Amount : {estimatedAmount}, Treatment Cost : {treatmentCost}, Patient ID : {patientId}");
                var patientDetails = $"Patient Name : {patientName}, Date Of Birth : {dateOfBirth}, Hospital : {hospital}, Patient Status : {patientStatus}, Hospitalization Required: {hospitalizationRequired}, Patient Age: {patientAge}, Consultation Fee : {consultationFee}, Estimated Amount : {estimatedAmount}, Treatment Cost : {treatmentCost}, Patient ID : {patientId}";
                PatientInOut.Set(context, PatientInOut.ToString());
                ShowPatientDetails.Set(context, patientDetails);
                tracingService.Trace("Patient Details using input and output parameters Workflow Ended.");
            catch(Exception ex)
                throw new InvalidPluginExecutionException(ex.Message);


The below screen shot will show you the representation of the Input arguments once after you successfully build and deploy the above custom workflow code activity.


The most used JavaScript Methods for Dynamics CRM v9.x

Here’s a quick reference guide covering Microsoft Dynamics CRM syntax for common java script requirements for v9.x.

Most of the examples are provided as functions that you can easily test in the On Load and On Save by generating form Context from execution Context.

//Execute all On Load events here

function OnLoad(executionContext) {
try {
//Get the form context
var formContext = executionContext.getFormContext();
//Sample code for On Load Event
Xrm.Utility.alertDialog("This is an alert for On Load Event.");
catch (e) {

Continue reading “The most used JavaScript Methods for Dynamics CRM v9.x”

The most used code snippets in Dynamics365