web
You’re offline. This is a read only version of the page.
close
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

I have the same question (0)
  • Suggested answer
    Adrian Begovich Profile Picture
    1,027 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

Responsible AI policies

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

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans