Convert Integer to Code

FPocoFPoco Member Posts: 35
Hi forum

how I make to convert an integer field into a code field?

thanks

Comments

  • matttraxmatttrax Member Posts: 2,309
    code_variable := FORMAT(integer_variable);
  • FPocoFPoco Member Posts: 35
    I can do for that way ??

    count := 0;

    if find ('-') then
    repeat
    count += 1
    until next = 0;

    code := FORMAT(count);
  • MTCMTC Member Posts: 159
    Format does the job, but what are you trying to do exactly?
  • FPocoFPoco Member Posts: 35
    I need to compose a numerator where one another one has a fixed part that will be id of the user and another one who will be an count, must have this aspect xxxabc001
  • David_CoxDavid_Cox Member Posts: 509
    FPoco wrote:
    I need to compose a numerator where one another one has a fixed part that will be id of the user and another one who will be an count, must have this aspect xxxabc001

    Why not just add the user ID to the table, and if your Numerator (My Code) is not the primary key then something like:

    SETCURRENTKEY("USER ID",My Code");
    SETRANGE("USER ID",USERID);
    IF FINDLAST THEN
    NextMyCode := INCSTR("My Code")
    ELSE
    NextMyCode := USERID + '001';

    MyRecVariable.INIT;
    MyRecVariable."My Code" := NextMyCode;
    MyRecVariable."USER ID" := USERID;
    MyRecVariable.INSERT;

    Or another option if you are using the user setup table, is to create a field and use a number series for each user and the NoSeriesManagement code unit to return the next number!

    with a Starting Number of xxxabc000 then it is easy to change if the requirement changes.

    David
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • MTCMTC Member Posts: 159
    Would a FINDLAST or a FIND('+') and then an INCSTR on the code work?

    Rec.SETFILTER(field,xxx);

    IF Rec.FINDLAST THEN
    BEGIN
    newcode := INCSTR(Rec.actualcode);
    END;

    Maybe it will, maybe it wont?
  • FPocoFPoco Member Posts: 35
    the id is not id of navision is of a new table that I only created for this program. This will go to identify the referring user in the numerator. The first part of the numerator is a field text but fixed it will not go to suffer to alterations the second part will be selected by the people whom the numerator will create and third he will be the accountant who will go being developed consonant its use.
  • David_CoxDavid_Cox Member Posts: 509
    FPoco wrote:
    the id is not id of navision is of a new table that I only created for this program. This will go to identify the referring user in the numerator. The first part of the numerator is a field text but fixed it will not go to suffer to alterations the second part will be selected by the people whom the numerator will create and third he will be the accountant who will go being developed consonant its use.

    Same Code!

    MyRecVariable.SETCURRENTKEY("My User ID",My Code");
    MyRecVariable.SETRANGE("My User ID",MyTableUser.ID);
    MyRecVariable.IF FINDLAST THEN
    NextMyCode := INCSTR(MyRecVariable."My Code")
    ELSE
    NextMyCode := MyTableUser.ID + '001';

    MyRecVariable.INIT;
    MyRecVariable."My Code" := NextMyCode;
    MyRecVariable.INSERT;

    As I said in my last post, I would use the number series, if it is by user then add a field "No. Series" to your new user (Accountant) table, then your code will be like this:

    The starting number per user would be Constant + New User ID + 000 = 'xxxaaa000'

    MyTableUser.TESTFIELD("No. Series");
    MyRecVariable.INIT;
    MyRecVariable."My Code" :=
    NoSeriesMgt.GetNextNo(MyTableUser."No. Series",TODAY,TRUE);
    MyRecVariable.INSERT;

    UserA
    xxxUserA001
    xxxUserA002
    xxxUserA003

    UserB
    xxxUserB001
    xxxUserB002
    xxxUserB003

    You can use the one number series for all users starting at say 100

    MyTableUser.TESTFIELD("No. Series");
    MyRecVariable.INIT;
    MyRecVariable."My Code" := Constant + MyTableUser.ID +
    NoSeriesMgt.GetNextNo(MyTableUser."No. Series",TODAY,TRUE);
    MyRecVariable.INSERT;

    This will cause sorting problems due to your structure!
    xxxUserA101
    xxxUserA104
    xxxUserB102
    xxxUserB105
    xxxUserC103

    Consider "Entry No." as a primary key, then a secondary key with the New user ID, and a composite field created on insert, Constant + MyUser.ID+ FORMAT("Entry No.");

    Then you can sort as entered or by your composite Field!
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • David_CoxDavid_Cox Member Posts: 509
    MTC wrote:
    Would a FINDLAST or a FIND('+') and then an INCSTR on the code work?

    Rec.SETFILTER(field,xxx);

    IF Rec.FINDLAST THEN
    BEGIN
    newcode := INCSTR(Rec.actualcode);
    END;

    Maybe it will, maybe it wont?

    It will! :D
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • FPocoFPoco Member Posts: 35
    OK but i can do it in a form??
    I have a problem whit the count
Sign In or Register to comment.