web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

Simple custom activity plugin that retrieves and displays a value won't work

(0) ShareShare
ReportReport
Posted on by
Hi. Ignore the name of this plugin because at this point I'm only trying to achieve something very simple from which then I could build something more complex. But even the simplest thing will not work. I'm still fairly new to plugins and custom activities so if anyone can pinpoint what I'm doing wrong, I'd be really grateful. First, here is the code of this custom activity, and at this point I'm only trying to retrieve the contactid, convert it to string and then be able to display it in some string field out there after I run a workflow on demand:
 
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Workflow;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Activities;
namespace WheatonPluginDelta.Activities
{
    public class RetrieveRaceOfPerson : CodeActivity
    {
        //Required input:
        [RequiredArgument]
        [Input(/PersonReference/)]
        [ReferenceTarget(/contact/)]
        public InArgument<EntityReference> PersonRef { get; set; }
 
        [Output(/StringTest2/)]
        public OutArgument<string> StringTest2 { get; set; }
        protected override void Execute(CodeActivityContext executionContext)
        {
            ITracingService tracingService = executionContext.GetExtension<ITracingService>();
            IWorkflowContext workflowContext = executionContext.GetExtension<IWorkflowContext>();
            IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
            IOrganizationService orgService = serviceFactory.CreateOrganizationService(workflowContext.UserId);

            EntityReference personRef = PersonRef.Get(executionContext);
            var contact = orgService.Retrieve(/contact/, personRef.Id, new ColumnSet(/contactid/));
            StringTest2.Set(executionContext, contact[/contactid/].ToString());

        }
    }
}
 
Here is the setup of this custom activity where it asks for the input for the workflow:
 
//
 
And then I set up the output to be StringTest2 from the custom activity to go to any other field that is of type string. Then I run the workflow on demand, and it doesn't work! Field does not get populated with the person's contactid.
 
Can someone please enlighten me on what I'm doing wrong on something so simple?
 
Thanks.
I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

#2
ManoVerse Profile Picture

ManoVerse 62 Super User 2026 Season 1

#3
11manish Profile Picture

11manish 43

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans