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)

Plugin SDK

(0) ShareShare
ReportReport
Posted on by 250

Hello Everyone, my name is Taniguchi and i having trouble to get na id from a entity when i try to set, can anyone tell me what am i doing wrong ?

var prodAluguelId = entity.Id;

Entity prodAluguel = new Entity("rbs_produtodoaluguel");
                    prodAluguel.Attributes["rbs_produtodoaluguelid"] = prodAluguelId;
                    prodAluguel["rbs_valorunitario"] = new Money(valor);
                    service.Update(prodAluguel);

*This post is locked for comments

I have the same question (0)
  • Shaminderpal Singh Profile Picture
    1,565 on at

    Hi Taniguchi,

    Can you provide your full code and also highlight on which message and operation you are running this?

    -Shaminder

  • TaniSantos Profile Picture
    250 on at

    my  full code:

    if (entity.LogicalName != "rbs_produtodoaluguel") return;

                   try

                   {

                       var prodAluguelId = entity.Id;

                       var meuProdutoId = entity.GetAttributeValue<EntityReference>("rbs_produto_teste").Id;

                       QueryExpression queryProd = new QueryExpression("rbs_produtodoaluguel")

                       {

                           // Colunas da Busca

                           ColumnSet = new ColumnSet(

                                "rbs_produto_teste", "rbs_valorunitario"

                               )

                       };

                        //

                       var condicao = new ConditionExpression();

                       condicao.AttributeName = "rbs_produto_teste";

                       condicao.Operator = ConditionOperator.Equal;

                       condicao.Values.Add(meuProdutoId);

                       // Filtra os resultados pela condição

                       var filtro = new FilterExpression();

                       filtro.Conditions.Add(condicao);

                       queryProd.Criteria.AddFilter(filtro);

                       QueryExpression query = new QueryExpression("productpricelevel")

                       {

                           // Colunas da Busca

                           ColumnSet = new ColumnSet(

                               "pricelevelid", "productid", "amount"

                               )

                       };

                       //

                       var condicao2 = new ConditionExpression();

                       condicao2.AttributeName = "productid";

                       condicao2.Operator = ConditionOperator.Equal;

                       condicao2.Values.Add(meuProdutoId);

                       // Filtra os resultados pela condição

                       var filtro2 = new FilterExpression();

                       filtro2.Conditions.Add(condicao2);

                       query.Criteria.AddFilter(filtro2);

                       // var resultado recebe os dados da busca

                       var result1 = service.RetrieveMultiple(query);

                       decimal valor = 0;

                           foreach (var e in result1.Entities)

                           {

                           decimal _valor = e.GetAttributeValue<Money>("amount").Value;

                           valor += _valor;

                           }

                       Entity prodAluguel = new Entity("rbs_produtodoaluguel");

                       prodAluguel.Attributes["rbs_produtodoaluguelid"] = prodAluguelId;

                       prodAluguel["rbs_valorunitario"] = new Money(valor);

                       service.Update(prodAluguel);

                   }

                   catch (FaultException<OrganizationServiceFault> ex)

                   {

                       throw new InvalidPluginExecutionException("An error occurred in the FollowupPlugin plug-in.", ex);

                   }

                   catch (Exception ex)

                   {

                       tracingService.Trace("FollowupPlugin: {0}", ex.ToString());

                       throw;

                   }

               }

  • TaniSantos Profile Picture
    250 on at

    in debbugins says the following error:

    "FaultException`1: rbs_produtodoaluguel With Id = a6c0dcf8-b4fb-e811-a97d-000d3ac000c8 Does Not Exist"

  • Suggested answer
    Shaminderpal Singh Profile Picture
    1,565 on at

    I assume you are running this on pre update due to which your record is not yet created in the database. Instead of these lines-

    Entity prodAluguel = new Entity("rbs_produtodoaluguel");

                      prodAluguel.Attributes["rbs_produtodoaluguelid"] = prodAluguelId;

                      prodAluguel["rbs_valorunitario"] = new Money(valor);

                      service.Update(prodAluguel);

    just write this only - entity.Attributes["rbs_valorunitario"]=new Money(valor)  as there is no need to update on pre operation.

    -Shaminder

  • TaniSantos Profile Picture
    250 on at

    I m running this at pos operation in entity "Produto do Aluguel" because i want to set the value of value after i created the register

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi ,

    I think your code is correct just to make your plugin execution mode Asynchronous .

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 March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans