Options

counting records.

lallylally Member Posts: 323
Hi,


Please help. I am not much coder how to count records and it has to come in sales invoice report.
that means Example:

s. no item qty unit price amout
1 xx 1 100 100
2 yy 1 200 200
3 zz 1 100 100

so i want serial no increment that is 1, 2, 3...... depends up on records
i done some thing like this but i am not getting.
i defined variable count, data type = int
in sales Line trigger On pre dataitem count =0;
on after get record = count=count+1;
when try to save this i am getting error THE RETURN VALUE SHOULD BE USED FOR THIS FUNCTION.
please provide solution how to do this. I am learner in coding . please provide code and solution. Please explain step by step.

regards
lally

Comments

  • Options
    matttraxmatttrax Member Posts: 2,309
    Did you do this
    count = 0
    count = count + 1
    

    or this
    count := 0
    count := count + 1
    

    The latter is the correct way. When assign values to variables you must use the := operator.

    The = operator is used for comparisons and returns true or false.
  • Options
    SavatageSavatage Member Posts: 7,142
    Salesline."Line No" / 10000
    :mrgreen:
    :^o
  • Options
    davmac1davmac1 Member Posts: 1,283
    TempSalesLine.RESET;
    TempSalesLine.SETRANGE(Type,SalesHeader.Type);
    TempSalesLine.SETRANGE("Document No.",SalesHeader."No.");
    Count:=TempSalesLine.COUNT;
  • Options
    AlbertvhAlbertvh Member Posts: 516
    Hi
    Change your variable name as count is a reserved word in NAV.

    OnPreDataItem
    Ser := 0;

    OnAfterGetRecord
    Ser := Ser + 1;

    Hope this helps

    Albert
  • Options
    David_SingletonDavid_Singleton Member Posts: 5,479
    lally wrote:
    ...
    on after get record = count=count+1;
    when try to save this i am getting error THE RETURN VALUE SHOULD BE USED FOR THIS FUNCTION....

    COUNT is a reserved word in NAV, you can not use it as a variable name.

    If you are in the "Sales Line" section, define a variable NoOfLines, and add the code:
    NoOfLines := COUNT;
    

    that's all you need.
    David Singleton
  • Options
    lallylally Member Posts: 323
    Thanks David Singleton,


    I put u r code in sales line on pre data item and taken a report with 3 records.
    what i got every record showing 3 number at begining
    that 3 for Ist record
    3 for 2nd record
    3 for 3 rd record
    I dont want like this
    what i want
    1 for Ist record
    2 for 2nd record
    3 for 3rd record.................
    like this

    I tried u r code on after geet record in sales line.
    but it is giving same

    please provide solution.
    thanks in advance.
    lally
  • Options
    SavatageSavatage Member Posts: 7,142
    the sales line already have a "Line No" field. Now i'm not thinking my post was so crazy.
    recordno := Salesline."Line No" / 10000;
    

    OR
    On pre dataitem.
    recordno := 0;
    
    onaftergetrecord
    recordno := recordno + 1;
    

    David's post is about COUNT - like your post title says.
    It will give you the total amount of lines but this is not apparently what you are looking for.
  • Options
    lallylally Member Posts: 323
    Thanks Savatage,


    I done already in the down process same as waht u told now.
    I defined variable count, data type = int
    in sales invoice Line trigger On pre dataitem count =0;
    i put in sales invoice on after get record = count=count+1;
    when try to save this i am getting error THE RETURN VALUE SHOULD BE USED FOR THIS FUNCTION.
    please provide solution how to do this. I am learner in coding . please provide code and solution. Please explain step by step.
    can u explain about that line no code . where to write.


    thanks in advance
    lally
  • Options
    SavatageSavatage Member Posts: 7,142
    edited 2007-08-10
    if you read davids' post above...
    COUNT is a reserved word in NAV, you can not use it as a variable name.

    Have you tried ANY OTHER variable name?

    How about myCOUNT

    or
    Variable name: MyCount (type integer)
    onaftergetrecord add
    MyCount := Salesline."Line No." / 10000;

    that's it. Now make a text box & set the source to MyCount & display it on your report, or whatever you are trying to show it.
  • Options
    lallylally Member Posts: 323
    thanks savatage,



    i tried what u told .
    But it is giving error u have specified unknown variable "lineno"
    please provide solution.

    thanks and regards.
    lally
  • Options
    ufukufuk Member Posts: 514
    You have to declare LineNo as an integer type variable.
    Ufuk Asci
    Pargesoft
  • Options
    SavatageSavatage Member Posts: 7,142
    if you are putting this code on some report using the Sales Invoice Line Table then you don't need to declare it - you just need to type it correctly.
    In any programming you can't just assume the program will know what you're trying to do. "Similar" is never "the same"

    "Sales Invoice Line"."Line No."

    or if you are using the Sales Line Table then it would look like

    "Sales Line"."Line No."

    In fact if you are putting the code on the same dataitem as the field you usally do not have to add the "Sales Invoice Line" or "Sales Line" part. I did that so not to confuse and to make it a bit clearer about where the data is coming from.

    Maybe it's a translation thing but I would stop adding please provide solution at the end of the posts, it just doesn't sound nice, at least to me O:)

    Other things to consider...
    1) using the "Line No." instead of the MyCount := Mycount + 1 method is assuming your no going to do anything freaky with "Line No." in the future.
    2)When you count are you just wanting to count the lines of type "Item". You make no provisions for a blank text line or g/l account, etc.

    something you might want to think about
  • Options
    AlbertvhAlbertvh Member Posts: 516
    see my first post :whistle:
  • Options
    anirudh_laroiyaanirudh_laroiya Member Posts: 19
    Dear Lally
    Mention the following code in OnAfterGetRecord Trigger

    sno := sno + 1;

    This code will serve your purpose.

    Anirudh
    09876157998
Sign In or Register to comment.