Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

problems in Order sheet.

Posted on by 1,835

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.

7356.test01.png

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

  • Verified answer
    manish.yadav Profile Picture
    manish.yadav 1,835 on at
    RE: problems in Order sheet.

    Finally the issue is resolved by the help of microsoft expert "Murat Vezir".

    Than you very much.

    please close this thread.

  • manish.yadav Profile Picture
    manish.yadav 1,835 on at
    RE: problems in Order sheet.

    Dear Murat Ji,

    In item card, the certified field is option type field so in backend saving data is 0,1,2,3,4.

    Here my validation is not accepting the code. I have attached the screenshots.

    5658.test01.png

  • Muratvzr Profile Picture
    Muratvzr 743 on at
    RE: problems in Order sheet.

    github.com/.../NAVCodes

    SendMailFromEvent.fob

    SendMailFromEvent.txt

    I hope this ll help you

  • manish.yadav Profile Picture
    manish.yadav 1,835 on at
    RE: problems in Order sheet.

    Dear Murat Sir,

    Unfortunately, query is not resolved. I was confused. Again, I have write down my actual requirement. I think the below lines are easy to understand the issue.

    "Talking in respect to ITEM CARD, there is a drop-down option which comes with title “CERTIFIED”. Let us consider an example in reference to same and let the very order has 4 items out of which only two are certified, so while creating the Sale Order for the purpose items which are marked as certified should be acknowledged by the very recipient and also a mail should automatically get propagated to the person whose product are tagged as certified in the above Sale Order."

  • Suggested answer
    Muratvzr Profile Picture
    Muratvzr 743 on at
    RE: problems in Order sheet.

    You have to change your way to doing it. First your if code is wrong i think Maybe you should do something like this

    ///// new code

    'Create a bool variable to check you there is any of certificated product in this order

    SendMail = FALSE

    SalesLine.SETRANGE("Document Type",RecSalesHdr."Document Type");

    SalesLine.SETRANGE("Document No.",RecSalesHdr."No.");

    SalesLine.SETRANGE(Type,SalesLine.Type::Item);

    IF SalesLine.FINDSET THEN

    BEGIN

     Mail.CreateMessage('MKU Limited','nav-uat@mku.com','manish.yadav@mku.com','Sales Order No.: '+ RecSalesHdr."No.",'',TRUE);  

           Mail.AddCC('harsh.manglani@mku.com');

           Mail.AppendBody('Dear Sir/Madam,');

           Mail.AppendBody('<br><br>');

    REPEAT

    IF RecItem.GET(SalesLine."No.") THEN

    BEGIN

    IF  RecItem.Certified <> RecItem.Certified::" "  THEN;

           Mail.AppendBody('Item Name :'+RecItem.Name+'Sales Order is released, where items is NIJ Certified');

    SendMail = TRUE;

    END

    UNTIL SalesLine.NEXT=0;

    IF SendMail THEN

    Mail.Send;

    END

    ///// new code

  • manish.yadav Profile Picture
    manish.yadav 1,835 on at
    RE: problems in Order sheet.

    Dear Murat Sir,

    Now I have resolve my query, I have make a another function in my sendmail codeunit the code is below:

    NIJCertified(VAR RecSalesHdr : Record "Sales Header")

    ///// new code

    SalesLine.SETRANGE("Document Type",RecSalesHdr."Document Type");

    SalesLine.SETRANGE("Document No.",RecSalesHdr."No.");

    SalesLine.SETRANGE(Type,SalesLine.Type::Item);

    IF SalesLine.FINDSET THEN

    REPEAT

    IF RecItem.GET(SalesLine."No.") THEN

    BEGIN

    IF  RecItem.Certified = RecItem.Certified::" "  THEN;

           Mail.CreateMessage('MKU Limited','nav-uat@mku.com','manish.yadav@mku.com','Sales Order No.: '+ RecSalesHdr."No.",'',TRUE);  

           Mail.AddCC('harsh.manglani@mku.com');

           Mail.AppendBody('Dear Sir/Madam,');

           Mail.AppendBody('<br><br>');

           Mail.AppendBody('Sales Order is released, where items is NIJ Certified');

           Mail.Send;

    END

    UNTIL SalesLine.NEXT=0;

    ///// new code

    But now the issue is, if in sales line there have 4 items then mail is coming 4 times not for the particular items,

    but there have only single item is certified. Also How can I show the item name here,

    For this you can see my previous mail where have I attached the screenshots.

  • Suggested answer
    CDsilva Profile Picture
    CDsilva 4,184 on at
    RE: problems in Order sheet.

    Hi

    check the below link for sending mail syntax

    www.cloudfronts.com/send-email-attachment-vendor-response-purchase-order-workflow-nav-2017

  • manish.yadav Profile Picture
    manish.yadav 1,835 on at
    RE: problems in Order sheet.

    Dear Sir,

    Now, code is running. But mail is not going to concern person.

    In my sales line, there have 7 lines. In first line selected item is certified in Item card.
    But mail is not goining to concern person.

    I have attached the screenshots.

    4617.test01.png

    4617.test01.png

  • Muratvzr Profile Picture
    Muratvzr 743 on at
    RE: problems in Order sheet.

    I think there is some item no field is missing in your order maybe you enter free text and these lines getting this error. Your code can not find Items so you are getting this error for this. First make a filter for Sales Line type item and surrond your get code with if

    Here is your sample I am writing it on freetext and I cant debug it.

    SalesLine.SETRANGE("Document Type",SalesHeader."Document Type");

    SalesLine.SETRANGE("Document No.",SalesHeader."No.");

    SalesLine.SETRANGE("Type",Salesline.Type::Item);

    IF SalesLine.FINDSET THEN

    REPEAT

    IF RecItem.GET(SalesLine."No.") THEN

    BEGIN

    IF  RecItem.Certified = RecItem.Certified::" "  THEN;

    SMTpMail.AddBCC('manish.yadav@mku.com');

    END

    UNTIL SalesLine.NEXT=0;

    Maybe this should work if its not working I can connect you with teamviewer

  • manish.yadav Profile Picture
    manish.yadav 1,835 on at
    RE: problems in Order sheet.

    Dear Murat Sir,

    I have tried to applied the debugger, the following error messages generating. I have attached the screenshots.

    5047.test02.png

    5047.test02.png

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans