Copy document functionality - ignore blocked items

hairyjimhairyjim Member Posts: 99
edited 2005-09-16 in Navision Attain
When you use the copy document functionality can it:
1) Copy the quote description
2) Tell you that there are blocked items (but skip them) but still bring over the rest of the document.

Anyone know where in Report 292 I need to change to make this happen?

Cheers
Jim
Give a man a fish and he will eat for a day, teach a man to fish and he will drink beer allday.

Answers

  • KowaKowa Member Posts: 923
    In Report 292 the quote document number has to be copied in a new field in the Sales Header table (after the TRANSFERFIELDS statement) , the rest must be done in Codeunit 6620 "Copy Document Mgt" ( to find the quote sales lines and to skip the blocked items).
    Kai Kowalewski
  • hairyjimhairyjim Member Posts: 99
    Can I use CurrReport.SKIP in code units or is there a better way of skipping a line item?
    Give a man a fish and he will eat for a day, teach a man to fish and he will drink beer allday.
  • hairyjimhairyjim Member Posts: 99
    I found this in codeunit 6620:
              IF FromSalesLine.FIND('-') THEN
                REPEAT              
                IF FromSalesLine.Quantity > 0 THEN BEGIN
                    ToSalesLine."No." := FromSalesLine."No.";
                    ToSalesLine."Variant Code" := FromSalesLine."Variant Code";
                    ToSalesLine."Location Code" := FromSalesLine."Location Code";
                    ToSalesLine."Bin Code" := FromSalesLine."Bin Code";
                    ToSalesLine."Unit of Measure Code" := FromSalesLine."Unit of Measure Code";
                    ToSalesLine."Qty. per Unit of Measure" := FromSalesLine."Qty. per Unit of Measure";
                    ToSalesLine."Outstanding Quantity" := FromSalesLine.Quantity;
                    CheckItemAvailable(ToSalesHeader,ToSalesLine);
                   END;
                UNTIL FromSalesLine.NEXT = 0;
    

    This I believe to be the code that does the copying of sales lines to the new sales quote.

    The function call of: CheckItemAvailable(ToSalesHeader,ToSalesLine); I think I need to put in the IF statement just after the repeat so I can check before trying to copy, and if it comes back true then skip that record.

    I am not sure how to achieve this. Could someone please advise.

    Thanks
    Give a man a fish and he will eat for a day, teach a man to fish and he will drink beer allday.
  • KowaKowa Member Posts: 923
    Create an local Item record variable.
    After the REPEAT something like this:

    If FromSalesLine."Type" = FromSalesLine."Type"::Item then begin
    Item.get(FromSalesLine."No.");
    IF Item.Blocked THEN
    IF confirm('Item %1 is blocked and will not be copied',TRUE,FromSalesLine."No.") THEN;
    End;
    IF ((FromSalesLine."Type" = FromSalesLine."Type"::Item) AND NOT Item.Blocked) OR (FromSalesLine."Type" <> FromSalesLine."Type"::Item) then
    IF FromSalesLine.Quantity > 0 THEN BEGIN

    ....

    The confirm YES / NO buttons can both be used, as this is used only for display purposes here.
    Kai Kowalewski
  • hairyjimhairyjim Member Posts: 99
    Hmmm - actually I now realise the check happens on the sales line table.

    In the code there is the following lines:
      Type::Item:
        BEGIN
          GetItem;
          Item.TESTFIELD(Blocked, FALSE); //This is where it would check and fail blocked items
          Item.TESTFIELD("Inventory Posting Group");
          Item.TESTFIELD("Gen. Prod. Posting Group");
    
          Description := Item.Description;
          "Description 2" := Item."Description 2";
          GetUnitCost;
          "Allow Invoice Disc." := Item."Allow Invoice Disc.";
          "Units per Parcel" := Item."Units per Parcel";
          "Gen. Prod. Posting Group" := Item."Gen. Prod. Posting Group";
          "VAT Prod. Posting Group" := Item."VAT Prod. Posting Group";
          "Tax Group Code" := Item."Tax Group Code";
           "Item Category Code" := Item."Item Category Code";
          "Product Group Code" := Item."Product Group Code";
          Nonstock := Item."Created From Nonstock Item";
          "Profit %" := Item."Profit %";
          "Allow Item Charge Assignment" := TRUE;
    
          IF SalesHeader."Language Code" <> '' THEN
            GetItemTranslation;
    
          IF (Item.Reserve = Item.Reserve::Optional) THEN
            Reserve := SalesHeader.Reserve
          ELSE
            Reserve := Item.Reserve;
    
          VALIDATE("Unit of Measure Code",Item."Sales Unit of Measure");
        END;
    

    Now from what I have researched the copy document functionality works thus (ignoring Include header option):

    If you 'recalculate lines' any line that is blocked will stop the process. The error gets thrown from the sales line table, in the code posted above.

    If you do not 'recalculate lines' then all lines including blocked get copied to the new sales quote.

    Now I think I have two options.

    a) I modify the sales line table so that it respects the blocked items check but throws a friendly error which would allow the process to continue.

    b) I somehow manage to figure out which bit of code is used for not recalculating lines and modify it so that bit of code is fired for recalculating lines but throws a friendly error which would allow the process to continue.

    Which option do people think will work best in the grand scheme of things, or is there a much better and simpler way of doing this.
    Give a man a fish and he will eat for a day, teach a man to fish and he will drink beer allday.
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Hi,

    I would not change the salesline table.

    You should try to not have the blocked items in your copies salesorder.

    Navision does this for G/L accounts that have direct posting.

    Have a look in the function CopySalesLine in the Codeunit 6620.

    You wil find the following piece of code there:
        IF ToSalesLine.Type = ToSalesLine.Type::"G/L Account" THEN BEGIN
          ToSalesLine."No." := FromSalesLine."No.";
          IF GLAcc."No." <> FromSalesLine."No." THEN
            GLAcc.GET(FromSalesLine."No.");
          CopyThisLine := GLAcc."Direct Posting";
          IF CopyThisLine THEN
            ToSalesLine.VALIDATE("No.",FromSalesLine."No.");
        END ELSE
          ToSalesLine.VALIDATE("No.",FromSalesLine."No.");
    

    Notice that the boolean CopyThisLine is set to false is directposting if false.

    You need to program a similar thing if the item is blocked.

    If you need help with this, just ask.
  • hairyjimhairyjim Member Posts: 99
    Thanks for the reply.

    Yeah I could do with a little extra explaining as to how I can use this to allow quotes to be copied to another quote without copying blocked items but to continue processing if it does find a blocked record
    Give a man a fish and he will eat for a day, teach a man to fish and he will drink beer allday.
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Try:
        IF ToSalesLine.Type = ToSalesLine.Type::"G/L Account" THEN BEGIN 
          ToSalesLine."No." := FromSalesLine."No."; 
          IF GLAcc."No." <> FromSalesLine."No." THEN 
            GLAcc.GET(FromSalesLine."No."); 
          CopyThisLine := GLAcc."Direct Posting"; 
          IF CopyThisLine THEN 
            ToSalesLine.VALIDATE("No.",FromSalesLine."No."); 
        END ELSE 
          if ToSalesLine.Type = ToSalesLine.Type::"ITEM" THEN BEGIN  
           ToSalesLine."No." := FromSalesLine."No."; 
          IF Item."No." <> FromSalesLine."No." THEN 
            Item.GET(FromSalesLine."No."); 
          CopyThisLine := NOT Item."Blocked"; 
          IF CopyThisLine THEN 
            ToSalesLine.VALIDATE("No.",FromSalesLine."No."); 
        end else
          ToSalesLine.VALIDATE("No.",FromSalesLine."No."); 
    

    I hope it works, it should, but I have not tested.

    If you want realy neat programming you should do a case statement.
  • hairyjimhairyjim Member Posts: 99
    After a little bit of modifications this works a treat.

    When it does come across a line that is 'blocked' it does skip and carry n copying but it shows the following error after the batch copy has finished.

    "The document line(s) with a G/L account where direct posting is not allowed have not been copied ot the new document by the copy document batch job."

    Do you know where this message is thrown from, I would like to change it to say something more friendly such as "Certain items were not copied because they are blocked".

    Thanks for your help, I have really learned some nwe things while trying to do this over the last few days.
    Give a man a fish and he will eat for a day, teach a man to fish and he will drink beer allday.
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Change variable Text004 in Codeunit 6620.

    It is raised in the Function CopySalesDoc
    IF LinesNotCopied > 0 THEN
      MESSAGE(Text004);
    

    Better is to create a new message, and leave the Text004 as it is, for future upgrading.
  • hairyjimhairyjim Member Posts: 99
    =D>

    Most excellent.

    You and others in this thread have helped a great deal!

    Thankyou all.

    Jim
    Give a man a fish and he will eat for a day, teach a man to fish and he will drink beer allday.
Sign In or Register to comment.