Sales Order header force series no

Hi everyone, I'm having a little trouble trying to assign different series no according to the user logged in the NAV system to create a new sales order.

So my page Sales order have the "Sales header" table as source table and if i try to create a new record I want to have in the "posting no. series" the user posting no.
if I do this in the "OnNewRecord" trigger when I enter the page everything is ok but when i change anything it changes automatically to another series no.

So after a little debugging I found this piece of code in a "InitRecord" function in sales header table, so it's explained why I can't change in my page just the "posting no".

InitRecord()
SalesSetup.GET;

CASE "Document Type" OF
"Document Type"::Quote,"Document Type"::Order:
BEGIN
//soft,sn
IF InSeriesGroup(1) THEN
NoSeriesMgt.SetDefaultSeries("Posting No. Series",SeriesGroups."Posted Invoice")
ELSE BEGIN
//soft,en
User.GET(USERSECURITYID);
NoSeriesMgt.SetDefaultSeries("Posting No. Series",User."Posting No."); //returns MRVF1 (what i want)
//NoSeriesMgt.SetDefaultSeries("Posting No. Series",SalesSetup."Posted Invoice Nos."); // returns MRVFA

//soft,sn
END;

The problem is when I change the code

NoSeriesMgt.SetDefaultSeries("Posting No. Series",SeriesGroups."Posted Invoice") to
User.GET(USERSECURITYID);
NoSeriesMgt.SetDefaultSeries("Posting No. Series",User."Posting No.");

in my page I got the error that the series code "MRVF1" doens't exist.. and its not true.. in my user I have assign to my user this series on Posting no field, and in the series table is defined also as in the series line table.

What am I missing?

Answers

  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    edited 2018-06-28
    If you look into T36 Sales Header the code selecting appropriate number serie is already there. If you look closer there is a function which selects no series depending on document type:

    achda4xk1fnz.png

    It is pretty simple in standard NAV, and it should be relatively easy to modify it to return in specific circumstances the numer series you want:

    p7pb5yqxha57.png


    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • catiamatos1991catiamatos1991 Member Posts: 158
    edited 2018-06-29
    So my suggestion is to change the "Invoice" Document type and put

    My function is bigger than what you shown... in my sales header table.
    LOCAL GetNoSeriesCode() : Code[10]
    //soft,sn
    IF "Series Group" <> '' THEN
      IF SeriesGroups.GET("Series Group") THEN
        CASE "Document Type" OF
          "Document Type"::Quote:
            IF SeriesGroups.Quote <> '' THEN
              EXIT(SeriesGroups.Quote);
          "Document Type"::Order:
            IF SeriesGroups.Order <> '' THEN
              EXIT(SeriesGroups.Order);
         [b] "Document Type"::Invoice:
          BEGIN
            IF "Debit Memo" THEN
              BEGIN
                IF SeriesGroups."Debit Memo" <> '' THEN
                  EXIT(SeriesGroups."Debit Memo");
              END
            ELSE
              IF SeriesGroups.Invoice <> '' THEN
                EXIT(SeriesGroups.Invoice);
          END;[/b]
          "Document Type"::"Return Order":
            IF SeriesGroups.Return <> '' THEN
              EXIT(SeriesGroups.Return);
          "Document Type"::"Credit Memo":
            IF SeriesGroups."Credit Memo" <> '' THEN
              EXIT(SeriesGroups."Credit Memo");
          "Document Type"::"Blanket Order":
            IF SeriesGroups."Blanket Order" <> '' THEN
              EXIT(SeriesGroups."Blanket Order");
        END;
    
    IF UserSetup.GET(USERID) THEN
      IF UserSetup."Sales Series Group" <> '' THEN BEGIN
        SeriesGroups.GET(UserSetup."Sales Series Group");
        CASE "Document Type" OF
          "Document Type"::Quote:
            IF SeriesGroups.Quote <> '' THEN
              EXIT(SeriesGroups.Quote);
          "Document Type"::Order:
            IF SeriesGroups.Order <> '' THEN
              EXIT(SeriesGroups.Order);
          [b]"Document Type"::Invoice:[/b]
          BEGIN
            IF "Debit Memo" THEN
              BEGIN
                IF SeriesGroups."Debit Memo" <> '' THEN
                  EXIT(SeriesGroups."Debit Memo");
              END
            ELSE
           [b]   IF SeriesGroups.Invoice <> '' THEN
                EXIT(SeriesGroups.Invoice);[/b]
          END;
          "Document Type"::"Return Order":
            IF SeriesGroups.Return <> '' THEN
              EXIT(SeriesGroups.Return);
          "Document Type"::"Credit Memo":
            IF SeriesGroups."Credit Memo" <> '' THEN
              EXIT(SeriesGroups."Credit Memo");
          "Document Type"::"Blanket Order":
            IF SeriesGroups."Blanket Order" <> '' THEN
              EXIT(SeriesGroups."Blanket Order");
        END;
      END;
    //soft,en
    
    [b]CASE "Document Type" OF[/b]
      "Document Type"::Quote:
        EXIT(SalesSetup."Quote Nos.");
      "Document Type"::Order:
        EXIT(SalesSetup."Order Nos.");
     [b] "Document Type"::Invoice:[/b]
      //soft,sn
      BEGIN
        IF "Debit Memo" THEN
          EXIT(SalesSetup."Debit Memo Nos.")
        ELSE
      //soft,en
       [b] EXIT(SalesSetup."Invoice Nos.");[/b]
      END; //soft,n
      "Document Type"::"Return Order":
        EXIT(SalesSetup."Return Order Nos.");
      "Document Type"::"Credit Memo":
        EXIT(SalesSetup."Credit Memo Nos.");
      "Document Type"::"Blanket Order":
        EXIT(SalesSetup."Blanket Order Nos.");
    END;
    

    My series group table don't have any information, so I used the SalesSetup information...

    In this case I've changed to this ,
    "Document Type"::Invoice:
    BEGIN
        IF "Debit Memo" THEN
          EXIT(SalesSetup."Debit Memo Nos.")
        ELSE BEGIN
          User.GET(USERSECURITYID);
          Exit(User."Posting No.");
       END;
    END;
    

    But in the page, it changed when I press new the series "MRPV1" to "MRVFA"
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    Would you please next time use code quotation fdjnwlyir45o.png It really makes the code much more readable.

    I'd suggest to get all the custom code out to a separte function (or functions) and modify the GetNoSeriesCode() it much simple way:

    zxzvt4madsao.png

    This will allow you to test your own code and check the output (the number series) before it is passed to other functions:

    Then the first thing to try would be just this:
    LOCAL GetMySeriesCode() : Code[10]
      EXIT('MRVF1'); //or whatever series seems to be poblematic
    

    Later I would rebuild your logic based on "Series Group" and other fields inside GetMySeriesCode() bit by bit, testing every change by means of checking value returned in GetNoSeriesCode() to ensure result is expected and correct.

    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • catiamatos1991catiamatos1991 Member Posts: 158
    edited 2018-06-29
    After a little debug I found that If I use this lines of code in the end of my InitRecord function I have everything fine.. each user have the right series no. Although the problem is in the Sales Credit Memo, the posting no series field appears with the wrong series number, and I cant' figure a way to force it in the page "Sales Credit Memo", because the sales header table overwrites the posting no... this is what I thought
    IF "Document Type" = "Document Type"::"Order" THEN BEGIN
    User.GET(USERSECURITYID);
    "Posting No. Series" := User."Posting No.";
    END;
    

    And with this little piece of code the series is right in both pages. The code of series in table Sales header remain the same.
  • catiamatos1991catiamatos1991 Member Posts: 158
    edited 2018-06-29
    After a little debug I found that If I use this lines of code in the end of my InitRecord function I have everything fine.. each user have the right series no. Although the problem is in the Sales Credit Memo, the posting no series field appears with the wrong series number, and I cant' figure a way to force it in the page "Sales Credit Memo", because the sales header table overwrites the posting no... this is what I thought
    IF "Document Type" = "Document Type"::"Order" THEN BEGIN
    User.GET(USERSECURITYID);
    "Posting No. Series" := User."Posting No.";
    END;
    

    And with this little piece of code the series is right in both pages. The code of series in table Sales header remain the same.
  • krikikriki Member, Moderator Posts: 9,112
    [Topic moved from 'NAV/Navision Classic Client' forum to 'NAV Three Tier' forum]

    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.