Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

Question regarding C# coding for plugin...

(0) ShareShare
ReportReport
Posted on by

Hi folks,

So here is my question, we have 2 table

Quote 1 :N Quotelineitem

So in the table quotelineitem we have many rows that are related to the quote.

For now, I need help on the coding. I want to retrieve all rows in a subgrid where the quoteid = the actual form we're on and then I want to add some text to a specific field call arb_lineitemsid

The code below is able to get me the guid of the actual form I am on which is good but the rest doesn't really work... I need guidance.

EntityReference mfpquotelookup = (EntityReference)entity.Attributes["new_mfpquote"];

Guid QuoteID = mfpquotelookup.Id;
var mfpquotelookupID = mfpquotelookup.Id;
var mfpquotelookupname = mfpquotelookup.Name;
// entity.Attributes.Add("arb_lineitemsid", mfpquotelookupID + "HEY");

QueryExpression qe = new QueryExpression("new_mfpquotelineitem");
qe.Criteria.AddCondition("new_mfpquote", ConditionOperator.Equal, QuoteID);
EntityCollection Colmfpquotelineitems = service.RetrieveMultiple(qe);

foreach (var targetEntity in Colmfpquotelineitems.Entities)
{
entity.Attributes.Add("arb_lineitemsid", mfpquotelookupID + "HEY");
}

  • Suggested answer
    necsa Profile Picture
    3,455 on at
    RE: Question regarding C# coding for plugin...

    Hi,

    You can use FetchXML Builder in XRMTool Box and convert your FetchXml to Query Expression than work on it.

    Example:

    //Set condition Value
    var query_quoteid = "your actual quote ID";
    
    //Instantiate QueryExpression query
    var query = new QueryExpression("new_mfpquotelineitem");
    
    // Add columns to you want to edit
    query.ColumnSet.AddColumn("arb_lineitemsid");
    
    //Add filte query.Criteria
    
    query.Criteria.AddCondition("quoteid",ConditionOperator.Equal, query_quoteid);
    
    var result =service.RetieveMultiple(query);
    if(result?.Entities?.Count !=0)
    {
      //fetch them
      foreach(var item in result.Entites)
      {
        var updatedquotelineItem = new Entity("new_mfpquotelineitem");
        updatedquotelineItem["arb_lineitemsid"]= (Guid)query_quoteid; //if the field is lookup data typ
        //if field lookup you cannot add any Text. If the field Text field than you add text
    
        updatedquotelineItem.Id = item.Id;
        service.Update(updatedquotelineItem);
      }
    
    }

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 106

#3
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 82 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans