Skip to main content

Notifications

Announcements

No record found.

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

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

    0525.Untitled.png

  • Suggested answer
    Adrian Begovich Profile Picture
    1,025 Super User 2025 Season 1 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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans