Options

How to get a control's value of a Page

ShimoneShimone Member Posts: 25
edited 2012-06-08 in NAV Three Tier
Hi!

I created a new field in a Page (P95). The source expression is the field Comment of T44.
When I validate that field how can I get its value if it's not referred to a record?

Thanks - Simone

Answers

  • Options
    vijay_gvijay_g Member Posts: 884
    Shimone wrote:
    I created a new field in a Page (P95).
    Have you created this field in table or you simply add a textbox on page?

    What does this mean could you be more clear on it.
    Shimone wrote:
    When I validate that field how can I get its value if it's not referred to a record?
  • Options
    ShimoneShimone Member Posts: 25
    I created just a textbox on the page.

    I want to access to its temporary value. This textbox compares on the page like a field, but if you type a value on it and then you close and open the page the value is erased.

    I can't find out how to get this value, and memorize it in a table. I think I can do it in the OnValidate trigger.
  • Options
    vijay_gvijay_g Member Posts: 884
    You can use textbox to compare and show the value only but if you want to memorize value then you must need to add a field in table.

    if you type a value on it and want to save this in table field that you have to add then write code on onvalidate of this textbox.
  • Options
    ShimoneShimone Member Posts: 25
    vijay_g wrote:
    You can use textbox to compare and show the value only but if you want to memorize value then you must need to add a field in table.

    I know that. I need to know how to refer in the code to the text box. If it was a record I would use Rec.NameField.

    But it's not a record. I wnat to access it to memorize it on a table.

    And if I use CurrPage.NameField it doesn't work, because I need the temporary value, not the control.
  • Options
    vijay_gvijay_g Member Posts: 884
    Shimone wrote:
    But it's not a record. I wnat to access it to memorize it on a table.

    if you used variable in textbox and want value of this in related table then make a function in table and pass a parameter and call this from Onaftergetrecord trigger.
  • Options
    ShimoneShimone Member Posts: 25
    I know how to write in table. And I used a variable: I specified it on the SourceExpression property of the textbox.

    But this variable doesn't change value when I validate the textbox. This is the real problem, maybe I finally explain it correctly, sorry :-k
  • Options
    vijay_gvijay_g Member Posts: 884
    A variable can't hold value after you close the object(except only if you have set Savevalues property of page to yes).

    if you are calculating value to show in this control for each line then how can it show you the value(after reopen this page) that you type on this.

    Hope now it's clear to you.
  • Options
    ShimoneShimone Member Posts: 25
    I don't close the page. I keep it open, and I want that when I type something in the textbox the variable assumes that text. Is there a specific event? It should be OnValidate but it doesn't work
  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,503
    Can you be more clear what exactly you need with example and WHY?
  • Options
    ShimoneShimone Member Posts: 25
    Can you be more clear what exactly you need with example and WHY?

    A customer wants an additional field in P95 (Sales Quote Subform). We don't want to add fields in the table, so we thought: "Let's add a field (Date Supporto) only in the page, with SourceExpr property assigned to a variable (DateSupporto). Each time the customer writes something in this field that value is stored in the Sales Comment Line (T44). So we don't create new columns."

    Here is the code. The record variable Commenti2 refers to the Sales Comment Line, and this is the code I wrote in the trigger OnValidate of field Date Supporto in Page 95.


    IF Commenti2.GET("Document Type","Document No.","Line No.",10000) THEN BEGIN
    Commenti2.Comment:= DateSupporto;
    Commenti2.MODIFY;
    END ELSE BEGIN
    Commenti2.INIT;
    Commenti2."Document Type":= "Document Type";
    Commenti2."No.":= "Document No.";
    Commenti2."Document Line No.":= "Line No.";
    Commenti2."Line No." := 10000;
    Commenti2.Comment:=DateSupporto;
    Commenti2.INSERT
    END;
  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,503
    OK...now I understood your requirement..
    without opening comments page,you want to insert/updated comments...

    What problem are you facing in this?

    I tried your code on Form and its working fine..please Insert Workdate as Date while inserting ..
  • Options
    ShimoneShimone Member Posts: 25
    OK...now I understood your requirement..
    without opening comments page,you want to insert/updated comments...

    What problem are you facing in this?

    I tried your code on Form and its working fine..please Insert Workdate as Date while inserting ..

    Ok, now it works ... i made confusion with different Designers open of the same Page... I'm sorry, I'm a noob at this, thank you all for your help!

    One last thing: Why do I have to insert Work Date? Is it important?
  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,503
    Shimone wrote:
    One last thing: Why do I have to insert Work Date? Is it important?
    To know the date of the comment was created.
  • Options
    ChinmoyChinmoy Member Posts: 359
    edited 2012-06-05
    I may not have understood the problem well, but coming to your original issue, like "not able to read the value of the variable DateSupportTo from the Page". I did something similar on page 95,
    1. Declared a variable DateSupportTo as Date
    2. Added it to the last field in the subform page
    3. Created a Local function (DateSupportTo - in the properties select Local as Yes) and


    4. added the following code to the function:
    IF DateSupportTo = TODAY() THEN
    MESSAGE('Date entered is Today!');



    It works for me. I am not sure what you want to do with the storing part of the situation, but I guess if you can get the value you can always store it wherever you want to.. :)

    Was this what you wanted?
  • Options
    ShimoneShimone Member Posts: 25
    It's not exactly what I wanted but it's interesting, thank you very much :-)

    There is another problem now ](*,) ...
    Whene I create a new line in P95 (Sales wuote subform) and I compile the value of the field Date Supporto, the entry that I create in the Sales Comment Line with the code I wrote some posts ago (and that I copy here) is created with Document Line No. = 0, and not equal to the value of the line document.
    IF Commenti2.GET("Document Type","Document No.","Line No.",10000) THEN BEGIN
      Commenti2.Comment:= DateSupporto;
      Commenti2.MODIFY;
    END ELSE BEGIN
      Commenti2.INIT;
      Commenti2."Document Type":= "Document Type";
      Commenti2."No.":= "Document No.";
      Commenti2."Document Line No.":= "Line No.";
      Commenti2."Line No." := 10000;
      Commenti2.Comment:=DateSupporto;
      Commenti2.INSERT
    END;
    

    Is it that when you create a new line in any document the Document Line is equal to zero? Damn!
  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,503
    It means that the line no. is not yet assigned when you added the value in DateSupporto field..

    first insert all details and move cursor to next line or previos line and then insert the DateSupporto value..and check
  • Options
    ShimoneShimone Member Posts: 25
    It means that the line no. is not yet assigned when you added the value in DateSupporto field..

    first insert all details and move cursor to next line or previos line and then insert the DateSupporto value..and check

    Yes you are right... but it is so uncomfortable! It overwrite the comment of header :-(...

    I modified the code to avoid this:

    IF Commenti2.GET("Document Type","Document No.","Line No.",10000) THEN BEGIN
      IF "Line No." <> 0 THEN BEGIN      
        Commenti2.Comment:= DateSupporto;
        Commenti2.MODIFY;
      END ELSE
        DateSupporto := ''
    END ELSE BEGIN
      Commenti2.INIT;
      Commenti2."Document Type":= "Document Type";
      Commenti2."No.":= "Document No.";
      Commenti2."Document Line No.":= "Line No.";
      Commenti2."Line No." := 10000;
      Commenti2.Comment:= DateSupporto;
      Commenti2.INSERT
    END;
    

    But it remains uncomfortable.... any better ideas? :-k
  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,503
    Shimone wrote:
    But it remains uncomfortable.... any better ideas? :-k
    Click Line-->Comments and enter value :D
  • Options
    ShimoneShimone Member Posts: 25
    Shimone wrote:
    But it remains uncomfortable.... any better ideas? :-k
    Click Line-->Comments and enter value :D

    LOl :lol:

    In fact there is a bug.. if you :

    -select one line (for example the first line)
    -click Line-->Comment
    -select another line (for example second line)
    -click Line-->Comment

    It opens the comment for the first line!!!! You have to click Comment again to get the right ones!
  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,503
    Shimone wrote:
    In fact there is a bug.. if you :

    -select one line (for example the first line)
    -click Line-->Comment
    -select another line (for example second line)
    -click Line-->Comment

    It opens the comment for the first line!!!! You have to click Comment again to get the right ones!
    Its not true..
    If you are using standard navision..
  • Options
    BernardJBernardJ Member Posts: 57
    Shimone wrote:
    It's not exactly what I wanted but it's interesting, thank you very much :-)

    There is another problem now ](*,) ...
    Whene I create a new line in P95 (Sales wuote subform) and I compile the value of the field Date Supporto, the entry that I create in the Sales Comment Line with the code I wrote some posts ago (and that I copy here) is created with Document Line No. = 0, and not equal to the value of the line document.
    IF Commenti2.GET("Document Type","Document No.","Line No.",10000) THEN BEGIN
      Commenti2.Comment:= DateSupporto;
      Commenti2.MODIFY;
    END ELSE BEGIN
      Commenti2.INIT;
      Commenti2."Document Type":= "Document Type";
      Commenti2."No.":= "Document No.";
      Commenti2."Document Line No.":= "Line No.";
      Commenti2."Line No." := 10000;
      Commenti2.Comment:=DateSupporto;
      Commenti2.INSERT
    END;
    

    Is it that when you create a new line in any document the Document Line is equal to zero? Damn!
    It should work with a Currpage.SAVERECORD just before your code
  • Options
    ShimoneShimone Member Posts: 25
    BernardJ wrote:
    It should work with a Currpage.SAVERECORD just before your code

    I added it, but the "Line No." is always zero ...
  • Options
    ufukufuk Member Posts: 514
    Your requirement is similar to Shortcut Dimension functionality in gen. journal lines. You can have a look at this.
    A few times I implemented similar solutions and basically you have to do the following:
    Create a temporary record after the validation of your variable (if line hasn't been inserted)
    Copy temporary record to normal record after the line's insertion.
    Ufuk Asci
    Pargesoft
  • Options
    ShimoneShimone Member Posts: 25
    ufuk wrote:
    Your requirement is similar to Shortcut Dimension functionality in gen. journal lines. You can have a look at this.
    A few times I implemented similar solutions and basically you have to do the following:
    Create a temporary record after the validation of your variable (if line hasn't been inserted)
    Copy temporary record to normal record after the line's insertion.

    Where is created the temporary record? In a record variable?

    And how can I find the correct "Document Line No."?
  • Options
    ufukufuk Member Posts: 514
    Create 3 functions in the page. Call InsertComment function OnInsertRecord and OnValidate of DateSupporto field.

    1)InsertComment
    IF "Line No." = 0 THEN
      SaveToTempComment
    ELSE
      CopyFromTempComment;
    

    2) SaveToTempComment
    IF TempSalesCommentLine.GET("Document Type","Document No.","Line No.",10000) THEN BEGIN
      TempSalesCommentLine.Comment:= DateSupporto;
      TempSalesCommentLine.MODIFY;
    END ELSE BEGIN
      TempSalesCommentLine.INIT;
      TempSalesCommentLine."Document Type":= "Document Type";
      TempSalesCommentLine."No.":= "Document No.";
      TempSalesCommentLine."Document Line No.":= "Line No.";
      TempSalesCommentLine."Line No." := 10000;
      TempSalesCommentLine.Comment:=DateSupporto;
      TempSalesCommentLine.INSERT
    END;
    

    3) CopyFromTempComment

    IF TempSalesCommentLine.GET("Document Type","Document No.",0,10000) THEN BEGIN
      SalesCommentLine := TempSalesCommentLine;
      SalesCommentLine."Document Line No." := "Line No.";
      SalesCommentLine.INSERT;
      TempSalesCommentLine.DELETE;
    END;
    

    This code is only for give an idea on how to insert. You have to check it and modify upon your case. Also, you may require writing additional code to display your variable properly.
    Ufuk Asci
    Pargesoft
  • Options
    ShimoneShimone Member Posts: 25
    ufuk wrote:
    Create 3 functions in the page. Call InsertComment function OnInsertRecord and OnValidate of DateSupporto field.

    1)InsertComment
    IF "Line No." = 0 THEN
      SaveToTempComment
    ELSE
      CopyFromTempComment;
    

    2) SaveToTempComment
    IF TempSalesCommentLine.GET("Document Type","Document No.","Line No.",10000) THEN BEGIN
      TempSalesCommentLine.Comment:= DateSupporto;
      TempSalesCommentLine.MODIFY;
    END ELSE BEGIN
      TempSalesCommentLine.INIT;
      TempSalesCommentLine."Document Type":= "Document Type";
      TempSalesCommentLine."No.":= "Document No.";
      TempSalesCommentLine."Document Line No.":= "Line No.";
      TempSalesCommentLine."Line No." := 10000;
      TempSalesCommentLine.Comment:=DateSupporto;
      TempSalesCommentLine.INSERT
    END;
    

    3) CopyFromTempComment

    IF TempSalesCommentLine.GET("Document Type","Document No.",0,10000) THEN BEGIN
      SalesCommentLine := TempSalesCommentLine;
      SalesCommentLine."Document Line No." := "Line No.";
      SalesCommentLine.INSERT;
      TempSalesCommentLine.DELETE;
    END;
    

    This code is only for give an idea on how to insert. You have to check it and modify upon your case. Also, you may require writing additional code to display your variable properly.

    It's clever! But...
    ...in the end my boss decided to create new fields in table in the end :-)
    Thank you very much, everybody :)
Sign In or Register to comment.