Dear Experts,
I have write a mail code for show the total cost based on its inventory posting group and unit(global dimension code 1). But in output always comes up the single value. Please help me to short this. My base table is "Value Entry". In value entry there have multiple inventory posting group but in my output only come the single posting group.
Please find the cost details summary:
Item Group |
Unit |
Total Cost Amount |
Raw Material |
101 |
822,918,144.31 |
My code is below:
Mail.CreateMessage('ABC Limited','nav@ABC.com','manish.yadav@abc.com','Stock Valuation Report','',TRUE) ;
Mail.AppendBody('Dear Sir / Madam,');
Mail.AppendBody('<br><br>');
Mail.AppendBody('Please find the cost details summary:');
Mail.AppendBody('<br><br>');
Mail.AppendBody('<table border="1">');
Mail.AppendBody('<tr>');
Mail.AppendBody('<th align="center">Item Group</th>');
Mail.AppendBody('<th align="center">Unit</th>');
Mail.AppendBody('<th align="right">Total Cost Amount</th>');
Mail.AppendBody('</tr>');
TotalCostValue:=0;
ValueEntry.RESET;
ValueEntry.SETFILTER(ValueEntry."Posting Date",'%1..%2',0D,TODAY);
IF ValueEntry.FINDFIRST THEN BEGIN
ValueEntry.CALCSUMS("Cost Amount (Actual)");
ValueEntry.CALCSUMS("Cost Amount (Expected)");
TotalCostValue := ValueEntry."Cost Amount (Actual)"+ValueEntry."Cost Amount (Expected)";
END;
InventoryPostingGroup.RESET;
InventoryPostingGroup.SETRANGE(Code, ValueEntry."Inventory Posting Group");
IF InventoryPostingGroup.FINDFIRST THEN BEGIN
Mail.AppendBody('<td align="center">'+FORMAT(InventoryPostingGroup.Description)+'</td>');
END;
Mail.AppendBody('<td align="center">'+FORMAT(ValueEntry."Global Dimension 1 Code")+'</td>');
Mail.AppendBody('<td align="right">'+FORMAT(TotalCostValue)+'</td>');
Mail.AppendBody('</tr>');
Mail.AppendBody('</table>');
Mail.AppendBody('<br>');
Mail.AppendBody('<b>From</b>');
Mail.AppendBody('<br>');
Mail.AppendBody('NAVISION (ERP) System');
Mail.AppendBody('<HR>');
Mail.AppendBody('This is a system generated mail. Please do not reply to this email ID.');
Mail.Send;
*This post is locked for comments
let me try and will give you the feedback on tomorrow.
To loop for each InventoryPostingGroup record, you need to use FINDSET. I don't understand what you want to do with your above code, but I can imagine there are logical errors:
1) You sum the first retrieved Value Entry
2) You filter a single InventoryPostingGroup record by filtering for ValueEntry."Inventory Posting Group" value.
It's quite obvious that you have only one record with this code.
Maybe you want to do something like this?
InventoryPostingGroup.RESET;
InventoryPostingGroup.SETRANGE(Code, ValueEntry."Inventory Posting Group");
IF InventoryPostingGroup.FINDSET THEN //<-- HERE we loop through each Inventory Posting Group record
REPEAT
ValueEntry.RESET;
ValueEntry."SETRANGE(Inventory Posting Group", InventoryPostingGroup.Code); //<-- Here you select ALL the Value Entry record for this Inventory Posting Group
ValueEntry.SETFILTER(ValueEntry."Posting Date",'%1..%2',0D,TODAY);
IF ValueEntry.FINDFIRST THEN BEGIN
ValueEntry.CALCSUMS("Cost Amount (Actual)");
ValueEntry.CALCSUMS("Cost Amount (Expected)");
TotalCostValue := ValueEntry."Cost Amount (Actual)"+ValueEntry."Cost Amount (Expected)";
END;
//here you have the totals for an Inventory Posting Group, so do what you need...
UNTIL InventoryPostingGroup.NEXT=0;
Thank you for fast reply.
I have try with FIND('-') and findset...but always comes only 1 row. But I have many lines.
Inventory Posting Group | Global Dimension 1 Code | Value |
FG | 202 | 747021.8 |
SFG | 101 | 14305374.67 |
TRD | 201 | -374438 |
RM | 102 | 56010442.72 |
CS | 202 | 0 |
PM | 103 | 48675 |
SFG | 102 | 10582328.26 |
CS | 101 | -6980705.67 |
OP | 102 | 442852.56 |
FG | 101 | 210438276.7 |
OP | 101 | 26595735.62 |
RM | 101 | 387677390.2 |
FG | 102 | 79847791.34 |
PM | 101 | 1487799.39 |
the upper output I have develop through the sql server.
select [Inventory Posting Group],[Global Dimension 1 Code],SUM([Cost Amount (Actual)]+[Cost Amount (Expected)]) from [ABC Private Limited$Value Entry]
Group by [Inventory Posting Group],[Global Dimension 1 Code]
having [Global Dimension 1 Code]<>''
You're using FINDFIRST so you retrieve only 1 record here.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156