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 :
Microsoft Dynamics CRM (Archived)

Create Optionset value in Custom workflow

(0) ShareShare
ReportReport
Posted on by 242

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

I have the same question (0)
  • Suggested answer
    Adrian Begovich Profile Picture
    1,032 Moderator on at

    Hi Rocky,

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

  • madiri Profile Picture
    242 on at

    0525.Untitled.png

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans