Hi Guys,
Bit of background: I am not a NAV expert at all but I have just started at a new company as their IT admin.
They use NAV 2009 R2 but have parted ways (before I left) with the Partner due to their incompetence apparantly.
My boss has asked my to see if I could fix the Job Queue which doesn't run at all (can't figure out why just yet). There is a codeunit with code for several jobs and one "section" is to do with adjust costs.
Now, reading the manual there is inbuilt stuff in NAV to do Adjust Costs - Automatic Cost Adjustment & Adjust Cost Item Entries (i've yet to understand how they work but I've found the white paper) but the code used by the old Partner is this:
ItemApplnEntry.LOCKTABLE;
IF NOT ItemApplnEntry.FIND('+') THEN
EXIT;
ItemLedgEntry.LOCKTABLE;
IF NOT ItemLedgEntry.FIND('+') THEN
EXIT;
AvgCostAdjmtEntryPoint.LOCKTABLE;
IF AvgCostAdjmtEntryPoint.FIND('+') THEN;
ValueEntry.LOCKTABLE;
IF NOT ValueEntry.FIND('+') THEN
EXIT;
PostToGL:=TRUE;
IF ItemNoFilter <> '' THEN
Item.SETFILTER("No.",ItemNoFilter);
IF ItemCategoryFilter <> '' THEN
Item.SETFILTER("Item Category Code",ItemCategoryFilter);
InvtAdjmt.SetProperties(FALSE,PostToGL);
InvtAdjmt.SetFilterItem(Item);
InvtAdjmt.MakeMultiLevelAdjmt;
UpdateItemAnalysisView.UpdateAll(0,TRUE);
Can anyone tell me what this code does?
Is it neccessary?
Can I use the inbuilt stuff in it's place?
Thanks for any feed back!
0
Comments
Hi BBrown,
the real problem is that the job queue seems stop completely with nothing appearing in the Job Queue log. Sometimes, we can "kick" them in to life by changing the "Earliest Start Date / Time" but only sometimes.
Any thoughts?
Hi,
this is the code in codeunti 25000
Documentation()
OnRun(VAR Rec : Record "Job Queue Entry")
CASE "Parameter String" OF
'DailyInvoiceReport':DailyInvoiceReport;
'AdjustCosts':AdjustCosts;
END;
DailyInvoiceReport()
FileName:=RBMgt.ServerTempFileName('','.htm');
IF EXISTS(FileName) THEN
ERASE(FileName);
OrdersListReport.SAVEASHTML(FileName);
ReportDate:=CALCDATE('-1D',WORKDATE);
SenderName:='NAS';
SenderAddress:='domain@domain.com';
Recipients:='1stperson@domain.com;2ndperson@domain.com;3rdperson@domain.com';
Subject:=STRSUBSTNO('Orders and Invoices report on %1',ReportDate);
SMTPMail.CreateMessage(SenderName,SenderAddress,Recipients,Subject,'',TRUE);
SMTPMail.AddAttachment(FileName);
{
SMTPMail.AppendBody('<table>');
LineText:=STRSUBSTNO('<tr><td>%1</td><td align=right>%2</td><td align=right>%3</td></tr>',
'Invoice No.','Customer No.','Sales Value');
SalesInvoice.SETRANGE("Posting Date",ReportDate);
IF SalesInvoice.FINDSET THEN REPEAT
SalesInvoice.CALCFIELDS(Amount);
InvoiceTotal+=SalesInvoice.Amount;
LineText:=STRSUBSTNO('<tr><td>%1</td><td align=right>%2</td><td align=right>%3</td></tr>',SalesInvoice."No.",
SalesInvoice."Sell-to Customer No.",
FORMAT(SalesInvoice.Amount,0,'<Precision,2><standard format,1>'));
SMTPMail.AppendBody(LineText);
UNTIL SalesInvoice.NEXT=0;
SalesCredit.SETRANGE("Posting Date",ReportDate);
IF SalesCredit.FINDSET THEN REPEAT
SalesCredit.CALCFIELDS(Amount);
InvoiceTotal-=SalesCredit.Amount;
LineText:=STRSUBSTNO('<tr><td>%1</td><td align=right>%2</td><td align=right>%3</td></tr>',SalesCredit."No.",
SalesCredit."Sell-to Customer No.",
FORMAT(SalesInvoice.Amount,0,'<Precision,2><standard format,1>'));
SMTPMail.AppendBody(LineText);
UNTIL SalesCredit.NEXT=0;
LineText:=STRSUBSTNO('<tr><td>%1</td><td></td><td align=right>%2</td></tr>','Total',
FORMAT(InvoiceTotal,0,'<Precision,2><standard format,1>'));
SMTPMail.AppendBody(LineText);
SMTPMail.AppendBody('</table>');
}
SMTPMail.Send;
AdjustCosts()
ItemApplnEntry.LOCKTABLE;
IF NOT ItemApplnEntry.FIND('+') THEN
EXIT;
ItemLedgEntry.LOCKTABLE;
IF NOT ItemLedgEntry.FIND('+') THEN
EXIT;
AvgCostAdjmtEntryPoint.LOCKTABLE;
IF AvgCostAdjmtEntryPoint.FIND('+') THEN;
ValueEntry.LOCKTABLE;
IF NOT ValueEntry.FIND('+') THEN
EXIT;
PostToGL:=TRUE;
IF ItemNoFilter <> '' THEN
Item.SETFILTER("No.",ItemNoFilter);
IF ItemCategoryFilter <> '' THEN
Item.SETFILTER("Item Category Code",ItemCategoryFilter);
InvtAdjmt.SetProperties(FALSE,PostToGL);
InvtAdjmt.SetFilterItem(Item);
InvtAdjmt.MakeMultiLevelAdjmt;
UpdateItemAnalysisView.UpdateAll(0,TRUE);
The first bit sends a report to certain people. There is a problem with this bit as I cannot add or remove any email addresses. It just stop working completely.
The second bit is the adjust cost stuff
Also any user using Classic client must do the same.
Regarding Adjust cost, you must check all the prerequisites to see why it doesn't run.
you can run Adjust cost manually and see if you receive any error.
You must also make sure that NAS is not running in parallel with other jobs and table locking's occur at the same time.
One solution would be to run at the same time like NAS is doing the procedure manually (disable NAS) and you can see if on that time something else is happening (which is very possible since when you are running the procedure on different time some times it does run)