Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum

Can't set a value for OptionSet field Custom Step C# d365 CRM

Posted on by 20

I have old plugins used to create some records on some conditions.

whenever I add new code or create new plugin or Custom step in C# it just run with no error and don't work on the form.

QueryExpression query = new QueryExpression();
            query.EntityName = "inn_commissionsettings";
            var CommissionSettings = service.RetrieveMultiple(query);
            tracingService.Trace("Retrieved the Commission Settings");

            if (CommissionSettings != null)
            {
                foreach (var CommissionSetting in CommissionSettings.Entities)
                {
                    tracingService.Trace("entered the loop");
                    Entity ContractCommission = new Entity("inn_contractcommission");
                    ContractCommission["inn_contract"] = new EntityReference(this.CurrentEntity.Get(executionContext).LogicalName, this.CurrentEntity.Get(executionContext).Id);
                    tracingService.Trace("inn_contract done");
                    ContractCommission["inn_commissionsetting"] = new EntityReference(CommissionSetting.LogicalName, CommissionSetting.Id);
                    tracingService.Trace("inn_commissionsetting done");
                    ContractCommission["inn_commissiontype"] = CommissionSetting.GetAttributeValue<OptionSetValue>("inn_type");
                    tracingService.Trace("inn_commissiontype done");
                    var currentEntity = service.Retrieve(this.CurrentEntity.Get(executionContext).LogicalName, this.CurrentEntity.Get(executionContext).Id, new ColumnSet(true));
                    ContractCommission["inn_unit"] = currentEntity.GetAttributeValue<EntityReference>("inn_unit");
                    tracingService.Trace("inn_unit done");

                    try
                    {
                        service.Create(ContractCommission);
                    }
                    catch(Exception ex)
                    {
                        throw new InvalidPluginExecutionException("error " + ex);
                    }


  • Soloer Profile Picture
    Soloer 20 on at
    RE: Can't set a value for OptionSet field Custom Step C# d365 CRM

    Thanks A lot, the problem was that there is a workflow that run and update the same field I'm trying to set with the plugin.

    it was solved thanks

  • Kokulan Profile Picture
    Kokulan 18,048 on at
    RE: Can't set a value for OptionSet field Custom Step C# d365 CRM

    Could you share the code of that plugin please if possible?

  • Soloer Profile Picture
    Soloer 20 on at
    RE: Can't set a value for OptionSet field Custom Step C# d365 CRM

    Thanks a lot issue was solved, however I have another plugin with the same issue and I added this line and issue still exist :D

  • Verified answer
    Kokulan Profile Picture
    Kokulan 18,048 on at
    RE: Can't set a value for OptionSet field Custom Step C# d365 CRM

    Sorry i missed that part of your question.

    Is there any particular reason why you have not specified the columns to be pulled from your settings entity. Please add the line in RED to your code and see if it sets the values

              query.EntityName = "inn_commissionsettings";

               query.ColumnSet = new ColumnSet(true);

               var CommissionSettings = service.RetrieveMultiple(query);

  • Soloer Profile Picture
    Soloer 20 on at
    RE: Can't set a value for OptionSet field Custom Step C# d365 CRM

    Hi Kokulan

    the issue that I don't get any error. the code just run successfully!

  • Kokulan Profile Picture
    Kokulan 18,048 on at
    RE: Can't set a value for OptionSet field Custom Step C# d365 CRM

    Could you share the actual error message that you are getting?

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans