Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Create Optionset value in Custom workflow

Posted on by 240

HI,

I am trying to create optionset value in custom workflow but its saying 

You cannot start a transaction with a different isolation level than is already set on the current transaction error in Plugin.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Metadata;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Workflow;
using System.Activities;


namespace Importglo
{
    public  class Class1 : CodeActivity
    {
        protected override void Execute(CodeActivityContext executionContext)
        {


            ITracingService tracingService = executionContext.GetExtension<ITracingService>();
            IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
            IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
            try
            {



                ////Read configuration




                ////Read configuration
                QueryExpression optionsetconfig = new QueryExpression()
                {
                  EntityName = "ss_bulkoptionset",
                  ColumnSet = new ColumnSet(true),
                   Criteria =
               {
                  Conditions =
                           {
                               //new ConditionExpression("fz_name", ConditionOperator.Equal, "Configurations"),
                               //new ConditionExpression("statecode", ConditionOperator.Equal, 0)
                           }
                }
                };

                EntityCollection _Records = service.RetrieveMultiple(optionsetconfig);





                foreach (Entity _Entity in _Records.Entities)

                {
                    //  tracingService.Trace("accountPlugin: {0}", _Entity.Attributes["fz_optionset"]);
                    InsertOptionValueRequest insertOptionValueRequest =
                   new InsertOptionValueRequest
                   {
                       Value = Convert.ToInt16(_Entity.Attributes["ss_optionset"]),
                       OptionSetName = _Entity.Attributes["ss_name"].ToString(),
                       Label = new Label(_Entity.Attributes["ss_optionsetlabel"].ToString(), 1033)

                   };
                    //execute the request
                    InsertOptionValueResponse optionResponse =
                         (InsertOptionValueResponse)service.Execute(insertOptionValueRequest);
                   // tracingService.Trace("accountPlugin: {0}", _Entity.Attributes["fz_optionset"]);
                }












            }
            catch (Exception ex)
            {
                tracingService.Trace("accountPlugin: {0}", ex.ToString());
                throw;
            }
        }
        [Input("Test")]
        public InArgument<string> Test { get; set; }
    }
}


*This post is locked for comments

  • madiri Profile Picture
    madiri 240 on at
    RE: Create Optionset value in Custom workflow

    0525.Untitled.png

  • Suggested answer
    Adrian Begovich Profile Picture
    Adrian Begovich 21,009 Super User 2024 Season 2 on at
    RE: Create Optionset value in Custom workflow

    Hi Rocky,

    There might be a problem with the registration of the custom workflow. Can you show us how you registered it?

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans