[Newbie question] Form with temporary table

ferrisferris Member Posts: 23
I have a stupid problem.
I want to open a form (from menu) based on a temporary table.
I have create a C/AL global variabile myVar::Record and, in the form properties:
- SourceTablePlacement: Record
- SourceTableRecord: myVar (or the id, but is the same)
But I receive an error.
The sourceTable must be set?

Thanks very much.

Comments

  • krikikriki Member, Moderator Posts: 9,118
    Create a form that works on the real table.
    To use the form with a temptable, you can do it in 2 ways:
    1) FORM.RUNMODAL(FORM::"The Form",tmpTheTempTable); // "tmpTheTempTable" is the temptable

    2) put some code in some triggers:
    "OnFindRecord":
    tmp17.COPY(Rec);
    blnFound := tmp17.FIND(Which);
    Rec := tmp17;
    EXIT(blnFound);
    
    "OnNextRecord":
    tmp17.COPY(Rec);
    intResultSteps := tmp17.NEXT(Steps);
    Rec := tmp17;
    EXIT(intResultSteps);
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • BalelloBalello Member Posts: 61
    The first part of kriki answer is right, but the form is temporary only if called that way. For the second I don't Know but you shouldn't set the rec to the temporary table if you don't find it. So better "don't move". Subsequently:

    Form - OnFindRecord(Which : Text[1024]) : Boolean

    tmpTable.COPY(Rec);
    IF NOT tmpTable.FIND(Which) THEN
    EXIT(FALSE);
    Rec := tmpTable;
    EXIT(TRUE);

    Form - OnNextRecord(Steps : Integer) : Integer

    tmpTable.COPYFILTERS(Rec);
    LintCurrentSteps := tmpTable.NEXT(Steps);
    IF LintCurrentSteps <> 0 THEN
    Rec := tmpTable;
    EXIT(LintCurrentSteps);

    I tried this code a lot of times. It works well.
    If you decide for the second way you must be careful with the OnInsertRecord, OnModifyRecord, OnDeleteRecord of the form. The form must be not editable or if editable you must write code to avoid inserting record on "true table". You can handle that via this code:


    Form - OnModifyRecord() : Boolean
    tmpTable := Rec;
    tmpTable.MODIFY;
    EXIT(FALSE);

    The same for Delete or Insert.
    Remember you must modify,delete,insert the temporary table that is set has global variable on that form, and not the rec!

    To Kriki: remember.... my subject! :-)
    I don't envy anybody who caught up his aim. I travel gladly.
  • ferrisferris Member Posts: 23
    Thanks very much!
  • BGIBGI Member Posts: 176
    What doi you have to put on the omdeleterecord section?
    I tried different ways , but none of them seems to work

    tmpTable := Rec;
    tmpTable.delete;
    EXIT(FALSE);

    tried exit(true);
    tried currform.update(false);

    any ideas in what should work to delete one record in the form??
    Rgds
    Benny Giebens
  • BalelloBalello Member Posts: 61
    At first a little correction (wrong using of copy/paste):

    Form - OnNextRecord(Steps : Integer) : Integer

    tmpTable.COPY(Rec); //not copyfilters
    LintCurrentSteps := tmpTable.NEXT(Steps);
    IF LintCurrentSteps <> 0 THEN
    Rec := tmpTable;
    EXIT(LintCurrentSteps);

    BGI: On Ondelete you must write what you tried first:

    tmpTable := Rec;
    tmpTable.delete;
    EXIT(FALSE);

    Probably you wrote wrong code on other triggers (if it's OnNextRecord you now have the solution).
    I don't envy anybody who caught up his aim. I travel gladly.
  • ObiWanObiWan Member Posts: 21
    Hi!
    what about just filling out an recordvairable that is set to Temporary(yes).
    only to be used if the amount of records is not to hughe, then the loop will
    take some time..

    if myrec.find('-') then begin
    repeat
    tmprec.init;
    //populate the fields here.
    tmprec.insert;
    until myrec.next = 0;
    form.runmodal(Number,Tmprec);
    end;

    Now u can even use filters and so on! :lol:

    May the force be with u!
  • David_CoxDavid_Cox Member Posts: 509
    ObiWan wrote:
    Hi!
    what about just filling out an recordvairable that is set to Temporary(yes).
    only to be used if the amount of records is not to hughe, then the loop will
    take some time..

    have a look at the code from the posting and the content. ](*,)

    1. The form must have a record.
    2. if the form is editable, and the user edits or deletes the form record then you get an "Error".

    In the scenario's above you load the temp record, present this to the user, who can edit and delete records, then you can take the recordset back and process it, cool or what??! =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
  • BalelloBalello Member Posts: 61
    Moreover, this method will create a "stand alone" form based on a temporary table. This means that, no matter the way you call it, it's based on a temporary table and not on the database table.
    And as a consequence, you can create "document form" (meaning form with subform) based on a temporary table and a dependent temporary table.
    That can't be done with form.runmodal(formNo,temptable), because there's no way to call the subform that way. There's some work to do to mantain the "Header/Line" relation.... but it's possible (and I'm doing it for a customer).
    Really not a standard Navision programming... It's a kind of different "software architecture" for which no changes are made on the database until the user or a "saving on OnTimer" decides for it. So the system can process more record at once, or other things like that. As a different "software architecture", it's not the right answer to every question.... only a different way that can be considered. And, obviously, being all records on Ram... it has good performance.
    I don't envy anybody who caught up his aim. I travel gladly.
Sign In or Register to comment.