Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Plugin - ID Field

Posted on by 250

Hello Everyone.

I m having some trouble because my plugin only work in assincronous and i need to work at sincronous mode, when i debug says that "produto teste" id doesnt exist.

can anyone help me ?

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;
                }

*This post is locked for comments

  • Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Plugin - ID Field

    Hello,

    Revisit your logic and check you are referring correct fields, you have written query expression but not used this query expression ??

    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);

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Plugin - ID Field

    Hi,

    Where you have execute query expression queryProd?

    Try to execute query expression and get the rbs_produto_teste value from result2.

     var resul2 = service.RetrieveMultiple(queryProd);

  • Suggested answer
    Sreevalli Profile Picture
    Sreevalli 3,256 on at
    RE: Plugin - ID Field

    Hi,

    sometimes lookup field will not be loaded, retrieve the record with the lookup columns.

    Entity targetentity = service.reterive(entity.LogicalName, entity.Id, new ColumnSet("rbs_produto_teste"));

    var meuProdutoId =targetentity.attribute.containns("rbs_produto_teste")? targetentity.GetAttributeValue<EntityReference>("rbs_produto_teste").Id:Guid.Empty;

  • gdas Profile Picture
    gdas 50,085 on at
    RE: Plugin - ID Field

    Hi,

    I would suggest before raise new question for same code  ,  close first old thread,  I believe I have answered your question here but you did not verified. By closing thread means you are also helping some other people who will face similar issue In future with correct answer.

    community.dynamics.com/.../303845

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

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,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans