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)

Plugin - ID Field

(0) ShareShare
ReportReport
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

I have the same question (0)
  • gdas Profile Picture
    50,091 Moderator on at

    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

  • Suggested answer
    Sreevalli Profile Picture
    3,256 on at

    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;

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

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

  • Mahendar Pal Profile Picture
    45,095 on at

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

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