Dear Experts,
I have write a codeunit to send the "Sales Order Sheet" to the concern person. The code is working fine. And mail is going through the job queue.
In this mail functionality, when the sales order released. The pdf file is generatring through this code and send it to the concern person.
Also mail is going to item related person. Means that if in sales line the picked item is related to the fabric items. then mail will auto go to fabric item related person.
Now, I have added the "certified" option field in item card.(there have 4 option). Any option can be selected.
If the item is certified in item card and that item is selected in sales line...then the order sheet will go to senor boss. And if the item is not certified the mail will not go to senor boss.
I am unable to resolve it.
Item category wise report is running correctly.
How to add the item certified functionality. I have written the code for this, please check my code that is write or wrong and it is no write place.
That is my humble request.
The complete code is below:
SendOrderSheetDetails(RecID : RecordID)
//// live running code
RecRef.GET(RecID);
CLEAR(SMTpMail);
CLEAR(MKUOrderSheetDetailsTO); // OrderSheetDetails is a Report 50030 //MR-0007
CLEAR(MKUOrderSheetDetailsSO); // OrderSheetDetails is a Report 50002 //MR-0007
CLEAR(ItemVariantDetailsTO); // ItemVariantDetails is a Report 50033 //MR-0007
CLEAR(TempItemCategory);
CLEAR(OrderNo);
CLEAR(OrderType);
CLEAR(SD1);
CLEAR(TemplateCode);
CASE RecRef.NUMBER OF DATABASE::"Sales Header":
BEGIN
RecRef.SETTABLE(RecSO);
OrderNo := RecSO."No.";
OrderType := FORMAT(RecSO."MKU Order Type");
SD1:= RecSO."Shortcut Dimension 1 Code";
TemplateCode := RecSO."Gen. Journal Template Code";
RecSL.RESET;
RecSL.SETRANGE("Document Type",RecSO."Document Type");
RecSL.SETRANGE("Document No.",RecSO."No.");
IF RecSL.FINDSET THEN
REPEAT
IF RecItem.GET(RecSL."No.") THEN;
IF NOT TempItemCategory.GET(RecItem."Item Category Code") THEN BEGIN
TempItemCategory.INIT;
TempItemCategory.Code:= RecItem."Item Category Code";
TempItemCategory.INSERT;
END;
UNTIL RecSL.NEXT=0;
PdfDocPath :='Order Sheet No_ '+RecSO."No."+'.pdf'; //FileName
PdfDocPath := CONVERTSTR(PdfDocPath,'\','-');
PdfDocPath :=CONVERTSTR(PdfDocPath,'/','-');
Path := 'C:\Temp\'+PdfDocPath; // Directory + Path
// IF (RecSo."MKU Order Type" IN [RecSO."MKU Order Type"::"Testing Sample-R&D"]) AND (RecProdHdr."Gen. Journal Template Code" IN ['102TST','101TST']) THEN BEGIN
// ItemVariantDetails.USEREQUESTPAGE(FALSE);
// ItemVariantDetails.SETTABLEVIEW(RecPPoHdr);
// IF NOT ItemVariantDetails.SAVEASPDF(Path) THEN
// ERROR('PDF Creating Failed!\\ERROR:\\' + RecPPoHdr."No." +GETLASTERRORTEXT);
// END ELSE BEGIN
RecSo1.RESET;
RecSo1.SETRANGE("Document Type",RecSO."Document Type");
RecSo1.SETRANGE("No.",RecSO."No.");
MKUOrderSheetDetailsSO.USEREQUESTPAGE(TRUE);
MKUOrderSheetDetailsSO.SETTABLEVIEW(RecSo1);
//MKUOrderSheetDetailsSO.RUN;
IF NOT MKUOrderSheetDetailsSO.SAVEASPDF(Path) THEN
ERROR('PDF Creating Failed!\\ERROR:\\' + RecSO."No." +GETLASTERRORTEXT);
//END;
END;
DATABASE::"Transfer Header":
BEGIN
RecRef.SETTABLE(RecTO);
OrderNo := RecTO."No.";
OrderType := FORMAT(RecTO."MKU Order Type");
SD1:= RecTO."Shortcut Dimension 1 Code";
TemplateCode := RecTO."Gen. Journal Template Code";
SalespersonCode:=RecTO."Salesperson Code";
RecTL.RESET;
RecTL.SETRANGE("Document No.",RecTO."No.");
IF RecTL.FINDSET THEN
REPEAT
IF RecItem.GET(RecTL."Item No.") THEN;
IF NOT TempItemCategory.GET(RecItem."Item Category Code") THEN BEGIN
TempItemCategory.INIT;
TempItemCategory.Code:= RecItem."Item Category Code";
TempItemCategory.INSERT;
END;
UNTIL RecTL.NEXT=0;
PdfDocPath :='Order Sheet No_ '+RecTO."No."+'.pdf'; //FileName
PdfDocPath := CONVERTSTR(PdfDocPath,'\','-');
PdfDocPath :=CONVERTSTR(PdfDocPath,'/','-');
Path := 'C:\Temp\'+PdfDocPath; // Directory + Path
RecTo1.RESET;
RecTo1.SETRANGE("No.",RecTO."No.");
IF (RecTO."MKU Order Type" IN [RecTO."MKU Order Type"::"Testing Sample-R&D"]) AND (RecTO."Gen. Journal Template Code" IN ['101TO-008','102TO-006']) THEN BEGIN
ItemVariantDetailsTO.USEREQUESTPAGE(FALSE);
ItemVariantDetailsTO.SETTABLEVIEW(RecTo1);
IF NOT ItemVariantDetailsTO.SAVEASPDF(Path) THEN
ERROR('PDF Creating Failed!\\ERROR:\\' + RecTO."No." +GETLASTERRORTEXT);
END ELSE BEGIN
MKUOrderSheetDetailsTO.USEREQUESTPAGE(FALSE);
MKUOrderSheetDetailsTO.SETTABLEVIEW(RecTo1);
IF NOT MKUOrderSheetDetailsTO.SAVEASPDF(Path) THEN
ERROR('PDF Creating Failed!\\ERROR:\\' + RecTO."No." +GETLASTERRORTEXT);
END;
END;
END;
SMTpMail.CreateMessage('MKU Limited','NAV@mku.com','','MKU Order Sheet Details-'+OrderNo+' '+OrderType,'',TRUE);
SMTpMail.AppendBody('Dear Sir / Madam,');
SMTpMail.AppendBody('<br><br>');
SMTpMail.AppendBody('Please Find The Production Order Details in PDF Format:');
SMTpMail.AppendBody('<br><br>');
SMTpMail.AppendBody('Regards');
SMTpMail.AppendBody('<br>');
SMTpMail.AppendBody('MKU Sales Departments');
SMTpMail.AddAttachment(Path,PdfDocPath);
///mky Begin
SalesLine.RESET;
SalesLine.SETRANGE("Document Type",SalesHeader."Document Type");
SalesLine.SETRANGE("Document No.",SalesHeader."No.");
IF SalesLine.FINDSET THEN
REPEAT
RecItem.SETFILTER(RecItem.Certified,'<>%1',RecItem.Certified::" ");
IF RecItem.GET(SalesLine."No.") THEN;
SMTpMail.AddBCC('manish.yadav@mku.com');
UNTIL SalesLine.NEXT=0;
///mky End
GetReportFilters(SMTpMail,' ','MR-0007',91,'');
filtr := SD1;
GetReportFilters(SMTpMail,filtr,'MR-0007',91,'');
IF TempItemCategory.FINDSET THEN
REPEAT
GetReportFilters(SMTpMail,SD1,'MR-0007',5722,TempItemCategory.Code); ///filter (item category added)
UNTIL TempItemCategory.NEXT=0;
GetReportFilters(SMTpMail,'','MR-0007',80,TemplateCode);
GetReportFilters(SMTpMail,'','MR-0007',13,SalespersonCode);
SMTpMail.Send;
IF ERASE(Path) THEN;
Please help me to resolve it. I am doing write or wrong.
*This post is locked for comments