Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Query By Attribute

(0) ShareShare
ReportReport
Posted on by

Morning 

I'm trying to add existing products to a quote. I have the product number working fine it is just the unit of mesure id i'm having trouble with. the query i'm running is

QueryByAttribute queryun = new QueryByAttribute("uom");
query.AddAttributeValue("name", "Default Unit");
var unittype = service.RetrieveMultiple(queryun).Entities.FirstOrDefault();

The the outcome 

Entity newQuoteproductsEntity = new Entity("quotedetail");
newQuoteproductsEntity["uomid"] = unittype.ToEntityReference();

When ever i run this i get the error 

QueryByAttribute must specify a non-empty attribute array.

i have tried QueryByAttribute queryun = new QueryByAttribute("uomschedule");

with no joy. My question is how do i go about doing the above or can ichage the way i bring products into the quote and bring the whole product and all it's details. Below is the code i am using to pull the products i want

// Create a column set to define which attributes should be retrieved.
ColumnSet attributes = new ColumnSet(true);

Entity CurrentQuoteEntity = new Entity("quote");
var id = context.PrimaryEntityId;
CurrentQuoteEntity = service.Retrieve("quote", id, new ColumnSet("quoteid"));
//CurrentQuote.Get<EntityReference>(executionContext).Id, attributes);
Guid quoteid = CurrentQuoteEntity.Id;
// Create New Price List
Entity newquote = new Entity("quote");
newquote.Id = CurrentQuoteEntity.Id;
// newquote["MH900"] = MH900.Get<string>(executionContext);
service.Update(newquote);
decimal qant = 5m;
//return;
{
QueryByAttribute query = new QueryByAttribute("product");
query.AddAttributeValue("productnumber", "F0900H VMCSS RHD");
var product = service.RetrieveMultiple(query).Entities.FirstOrDefault();
QueryByAttribute queryun = new QueryByAttribute("uom");
query.AddAttributeValue("name", "Default Unit");
var unittype = service.RetrieveMultiple(queryun).Entities.FirstOrDefault();
// return;
Entity newQuoteproductsEntity = new Entity("quotedetail");
newQuoteproductsEntity["productid"] = product.ToEntityReference();
newQuoteproductsEntity["uomid"] = unittype.ToEntityReference();
newQuoteproductsEntity["quantity"] = qant;
newQuoteproductsEntity["quoteid"] = new EntityReference("quote", quoteid);
service.Create(newQuoteproductsEntity);

Kind Regards

*This post is locked for comments

  • RE: Query By Attribute

    I have found the solution. Instead of working out which entity and values i should be using. Checking i had typed the code correctly would of been a good start.

    I just realised query.addattributevalue should be queryun.add.....

    Simple mistake

    Cheers

    Dan

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans