Wednesday 6 June 2018

How to get language id in Dynamic CRM using custom workflow

how to get current user  language id in dynamic crm using custom workflow

Description:

In this example we explain that how to get user language in Dynamic CRM using custom workflow. Or how to find the CRM user language Id(LCID) from within C# custom code using custom workflow or plugin. Or how to get the language id of the current user using custom workflow in Dynamic CRM.

So here we demonstrate that how to get the userId and based on UserId we find the Language Id of the user using custom workflow or plugin in Dynamic 365.below is the code to get the Language Id of the current user and based on the Language you can perform the different activities as per your requirements.

below code will require two parameter that you have to pass when you call custom workflow from your workflow and based on that parameter it will get the Language ID of the current user of the Dynamic CRM and display on alert box.
Custom Workflow:

using System;
    using System.Activities;
    using System.ServiceModel;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Xrm.Sdk.Workflow;
    using Microsoft.Xrm.Sdk.Query;
    using System.Collections.Generic;
    using System.Linq;


public sealed class TranslateText : CodeActivity
{
  

    [RequiredArgument]
    [Input("User")]
    [ReferenceTarget("systemuser")]
    public InArgument<EntityReference> User { get; set; }

    [RequiredArgument]
    [Input("Lead")]
    [ReferenceTarget("lead")]
    public InArgument<EntityReference> Lead { get; set; }
public ITracingService tracingService;
        public IWorkflowContext context;
        public IOrganizationServiceFactory serviceFactory;
        public IOrganizationService service;   

    protected override void Execute(CodeActivityContext executionContext)
    {

tracingService = executionContext.GetExtension<ITracingService>();
            context = executionContext.GetExtension<IWorkflowContext>();
            serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
            service = serviceFactory.CreateOrganizationService(context.UserId);        EntityReference userReference = this.Lead.Get(executionContext);
        EntityReference systemuserReference = this.User.Get(executionContext);

        QueryExpression UserList = new QueryExpression("usersettings");
        UserList.ColumnSet = new ColumnSet(true);

        UserList.Criteria.AddCondition(

           "systemuserid",
            ConditionOperator.Equal,
            systemuserReference.Id
        );

        var UserLists = service.RetrieveMultiple(UserList);


        string LanguageId = Convert.ToString(UserLists.Entities[0].Attributes["uilanguageid"]);

        throw new InvalidWorkflowException("Current User Language Id is   :" + LanguageId);
    }
}



This entry was posted in :

0 comments:

Post a Comment