Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Sub Grids in Quote Form

Posted on by Microsoft Employee

Hi All

I am still having a nightmare with the rollup of values from a subgrid. I am unable to use a Rollup field because the values are calculated I have tried the below code with no luck it just seems to do nothing. I have placed it on the Onload and just out of interest when i changed a lookup field. I have tested the i have the sb_delieverableweight field name correct. i am using CRM 2016 The subgrid is named ProfitMargin and the item i want to roll up in the sub grid is sb_prodweight i want this to go to a field on the quote called sb_delieverableweight. I have tried java and a plugin based on the calculatedprice SDK i have just put the part below i have changed from the SDK other than that it is the same as the SDK example but i have had no joy with it. With the plugin i set the step as required on the calculateprice on the quotedetail entity. I will put both sets of code below. I would be really greatfull if someone could give me a step by step to get this working please

JS 

function RetrieveSubGridRecords() {
if (document.getElementById("ProfitMargin")) {
var grid = document.getElementById("ProfitMargin").control;
var total = document.getElementById("sb_deliverableweight").value
var ids = grid.get_allRecordIds();
var sum = 0.00;
var cellValue;
for(i = 0; i < ids.length; i++) {
var cellValue = grid.getCellValue('sb_prodweight',ids[i]);
var number = Number(cellValue.replace(/[^0-9\.]+/g,""));
sum = sum + number+106;
}
val2('s'+sum);
Xrm.Page.getAttribute("sb_deliverableweight").setValue(val2);
alert (val2)
}
else {
setTimeout("RetrieveSubGridRecords();", 2500);
}
}

Plugin

#region Calculate Quote Price
// Method to calculate price in a quote
private static void CalculateQuote(EntityReference entity, IOrganizationService service)
{
Entity e = service.Retrieve(entity.LogicalName, entity.Id, new ColumnSet("statecode"));
OptionSetValue statecode = (OptionSetValue)e["statecode"];
if (statecode.Value == 0)
{
ColumnSet columns = new ColumnSet();
columns.AddColumns("totaltax", "totallineitemamount", "totalamountlessfreight", "discountamount");
Entity quote = service.Retrieve(entity.LogicalName, entity.Id, columns);

QueryExpression query = new QueryExpression("quotedetail");
query.ColumnSet.AddColumns("sb_prodweight", "priceperunit");
query.Criteria.AddCondition("quoteid", ConditionOperator.Equal, entity.Id);
EntityCollection ec = service.RetrieveMultiple(query);
quote["sb_deliverableweight"] = 0;

decimal total = 0;
decimal discount = 0;
decimal tax = 0;

for (int i = 0; i < ec.Entities.Count; i++)
{
total = total + ((decimal)ec.Entities[i]["sb_prodweight"]);
service.Update(ec.Entities[i]);
}

quote["sb_deliverableweight"] = total;

}

Many Thanks

Dan

*This post is locked for comments

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,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans