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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

For custom workflow activities, is it possible to retrieve a user based on a value from a lookup field?

(0) ShareShare
ReportReport
Posted on by

Hello,

Im looking for suggestions or documentation that will lead me in the right direction. The scenario is we have a lead and based on the lookup field (a geography-region zone etc...) it will retrieve a user. I will then call this workflow activity in a workflow in CRM and assign that user to the lead. 

thanks, 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    MihirShah Profile Picture
    4,036 on at
    RE: For workflow activities, is it possible to assign a user a lead based on a value from a lookup field?

    Hi CRMMax,


    This should be simple to do using a workflow on create of the Lead.

    Use the assign function referred in the link below.

    https://technet.microsoft.com/en-us/library/dn531057.aspx

    regards,


    Mihir

  • Suggested answer
    Nadeeja Bomiriya Profile Picture
    6,804 on at
    RE: For custom workflow activities, is it possible to assign a user a lead based on a value from a lookup field?

    Hi CRMMax,

    Here's a sample code and documentation as requested.

    // Create the Request Object and Set the Request Object's Properties
    AssignRequest assign = new AssignRequest
        {
            Assignee = new EntityReference(SystemUser.EntityLogicalName,
                _otherUserId),
            Target = new EntityReference(Account.EntityLogicalName,
                _accountId)
        };
    
    
    // Execute the Request
    _service.Execute(assign);

    https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.assignrequest.aspx

    You could use OOTB workflow step to Assign a user to a record as well, if the number of different conditions you have to check are not too high.

  • Community Member Profile Picture
    on at
    RE: For custom workflow activities, is it possible to retrieve a user based on a value from a lookup field?

    Hi have updated my question to be more specific. I am having trouble with the activity that will be called in the workflow as a step, I want to retrieve a user based on a zone like a zip code.

  • Verified answer
    Nadeeja Bomiriya Profile Picture
    6,804 on at
    RE: For custom workflow activities, is it possible to retrieve a user based on a value from a lookup field?

    Hi CRMMax,

    There's a more generic technique I use for this kind of scenarios.  You can configure a custom workflow activity to receive a FetchXML query and additional parameters as inputs.  Then you can call the query and return the record as an EntityReference, where you can use in other steps.

    public class GetContact : CodeActivity
    {
    	[RequiredArgument]
    	[Input("FetchXML Query")]
    	public InArgument<string> FetchXmlQuery { get; set; }
    
    	[Input("FetchXML Query Format Argument 1")]
    	public InArgument<string> FetchXmlQueryFormatArg1 { get; set; }
    
    	[Input("FetchXML Query Format Argument 2")]
    	public InArgument<string> FetchXmlQueryFormatArg2 { get; set; }
    
    	[Input("FetchXML Query Format Argument 3")]
    	public InArgument<string> FetchXmlQueryFormatArg3 { get; set; }
    
    	[Input("FetchXML Query Format Argument 4")]
    	public InArgument<string> FetchXmlQueryFormatArg4 { get; set; }
    
    	[Input("FetchXML Query Format Argument 5")]
    	public InArgument<string> FetchXmlQueryFormatArg5 { get; set; }
    
    	[ReferenceTarget("contact")]
    	[Output("Entity Reference")]
    	public OutArgument<EntityReference> EntityRef { get; set; }
    
    	protected override void Execute(CodeActivityContext context)
    	{
    		var entityReference = new EntityReference();
    
    		try
    		{
    			var serviceFactory = context.GetExtension<IOrganizationServiceFactory>();
    			var service = serviceFactory.CreateOrganizationService(Guid.Empty); //Use current user's ID
    
    			var collection = service.RetrieveMultiple(new FetchExpression(GetFormattedFetchQuery(context)));
    
    			if (collection != null && collection.Entities != null && collection.Entities.Count() > 0)
    			{
    				entityReference = collection.Entities.FirstOrDefault().ToEntityReference();
    				EntityRef.Set(context, entityReference);
    			}
    		}
    		catch (Exception ex)
    		{
    
    		}
    	}
    
    	private string GetFormattedFetchQuery(CodeActivityContext context)
    	{
    		var query = this.FetchXmlQuery.Get(context);
    		return String.Format(query,
    			this.FetchXmlQueryFormatArg1.Get(context),
    			this.FetchXmlQueryFormatArg2.Get(context),
    			this.FetchXmlQueryFormatArg3.Get(context),
    			this.FetchXmlQueryFormatArg4.Get(context),
    			this.FetchXmlQueryFormatArg5.Get(context));
    	}
    }


    This example returns a Contact record, based on the FetchXML query.  You can do similar thing to get the User.  You can pass the zone in FetchXmlQueryFormatArg1 argument.  Inside the FetchXML query you can type {0} where you want to insert the first argument.

  • Community Member Profile Picture
    on at
    RE: For custom workflow activities, is it possible to retrieve a user based on a value from a lookup field?

    Hello

    I would like to recommend Tenfold for this integration.

    Our company Tenfold supports integration for MS Dynamics. Our CTI solution offers various functions to help you automate your sales call workflow like click to dial, call logging, easy task creation, among others. You can read more about the benefits of a Tenfold integration here: www.tenfold.com/.../dynamics

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans