1. Open Visual Studio
  2. Take new project
  3. Search and select Class Library(.NET Framework)
  4. Change the name
  5. Change the Destination of the folder
  6. Click create

Next,
Enter the below Code

using System;

using System.Activities;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using Microsoft.Crm.Sdk.Messages;

using Microsoft.Xrm.Sdk;

using Microsoft.Xrm.Sdk.Query;

using Microsoft.Xrm.Sdk.Workflow;

    namespace test.CustomActivities

{

    public class AddContacttoMktgList : CodeActivity

    {

        [RequiredArgument]

        [Input(“Contact”)]

        [ReferenceTarget(“contact”)]

        public InArgument<EntityReference> Contact { get; set; }

        [RequiredArgument]

        [Input(“MarketingList”)]

        [ReferenceTarget(“Vinay”)]

        public InArgument<EntityReference> MarketingList { get; set; }

        protected override void Execute(CodeActivityContext executionContext)

        {

            var tracingService = executionContext.GetExtension<ITracingService>();

            var context = executionContext.GetExtension<IWorkflowContext>();

            var serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();

            var service = serviceFactory.CreateOrganizationService(context.UserId);

            var contact = this.Contact.Get<EntityReference>(executionContext);

            var mktgList = this.MarketingList.Get<EntityReference>(executionContext);

            if (contact != null && mktgList != null)

            {

                AddMemberListRequest amReq = new AddMemberListRequest();

                amReq.EntityId = contact.Id;

                amReq.ListId = mktgList.Id;

                AddMemberListResponse amRes = (AddMemberListResponse)service.Execute(amReq);

                                              }

                                }

                    }

}

Next
Right Click on your solution,
Click Manage NuGet Packages

Next
Install below packages  showing in the picture

  • Right Click on the (.cs),
  • Next Click Properties
  • After Click Signing,
  • Click Sign the assembly,
  • Click on the box,
  • Select New,
  • Enter Some name,
  • Unselect the Password protect,
  • Save.

Now, Right Click on your solution and click Build>
Final Output

Now Open XRMtoolBox,
Next install and open the Plugin Registration

Click Register and then Click Register New Assembly
upload .dll file created from visual studio
After Selecting the File,
Click Register Selected Plugins

After that finally it was Registered to our organization through Xrm

 

Next
Open Sales Hub app
Copy the Reference Target of marketing list (vinay)

Next

  1. In the, Marketing List Click new
  2. Next, Paste the name that we copied from the visual studio,
  3. Click Targeted At and select Contact
  4. Click Save and Close

Next

Go to the Processes and click new then enter the details

  1. Enter Practice Name
  2. Category will be workflow
  3. Entity will be contact
  4. And select Run this workflow in the background
  5. Finally Click ok

  1. After Opening,
    Change scope to the organization
  2. Next click on Add step
  3. Then we will find the triggers that we have registered from the XRMToolBox
  4. Select the trigger

 

Next
After we will see like this.
Next, Click Set Properties

After opening set properties,

  1. Fill first one with contact
  2. Second one as what we created in the marketing list (vinay)
  3. After click save and close

Next,

1.Click Save

2.After Click Activate

To see the workflow is working or not

Go to the Marketing List and open the list that we have created

After Opening,

1.Click on the members,

2.Finally we can see the contacts here Successfully