Create Item with wizard

I am trying to make a wizard for creating items. I have made it in the same way as the form “Create To Do”. It works like this: 1. Create temporary variable (Item) 2. Call form with tempoary item 3. Create item from temporary item (In the wizard) 4. Finished My problem is: I call this function from the Item Card. When I finish the wizard I want to be positioned at the new record but I am positoned at the same record as I started from. My code looks like this: TempItem.INIT; TempItem."No." := ''; TempItem.INSERT; IF FORM.RUNMODAL(FORM::"Create Item",TempItem) = ACTION::OK THEN NewItemNo := TempItem."No." ELSE NewItemNo := ''; IF NewItemNo <> '' THEN GET(NewItemNo); I never receive the new “Item No.” from the temporary record. If I define the form as a variable. How do I call that form with a temporary record? or How do I receive the new Item No. with the call I made?

Hi Magnus, I think the problem is that the “Finish” button does not have the PushAction “OK”, so your FORM.RUNMODAL does not return “OK”. Change the PushAction and it should work. Regards, Mark

Hi Mark! PushAction is OK. I think you misunderstood my problem. The wizar works fine. I can create a new item. My problem is that my code don’t know witch item I have created. I want to stand on the new item i have created after the wizard.

Ok, if the PushAction is ‘Ok’ then you should check if the “No.” of the newly created item is returned to the TempItem. Probably this still has the value ‘’ (Blank). You cannot return the “No.” of the new item to the TempItem because this will require a rename. You can put the value in the “No. 2” field of the TempItem. Then you get IF FORM.RUNMODAL(FORM::“Create Item”,TempItem) = ACTION::OK THEN NewItemNo := TempItem.“No. 2” ELSE NewItemNo := ‘’; Only problem with this code is that only you will know why to get it with the “No. 2” field, which is not a logical thing. Better maybe is to make the wizard a Variable Form and define a function with a returnvalue and return the “No.” of the new created Item. Regards, Mark

It doesn’t work with “No. 2”. TempItem is not returned. I have tried to make the form a variable, but how do I call the form with a temporary variable?

[:I] Oops, did not thought of that. No can do that. On a temprecord you cannot run varable forms. — The fact that the “No. 2” thing does not work strages me. Have you put in the code TempItem.“No. 2” := RealItem.“No.”; ??? in the wizard after inserting the Item? If it doesnot work we have to think of someting else. Regards, Mark

quote:

The fact that the “No. 2” thing does not work strages me. Have you put in the code TempItem.“No. 2” := RealItem.“No.”; ??? in the wizard after inserting the Item?

I actually did: TempItem.“No. 2” := Item.“No.”; TempItem.MODIFY;

Ok. I did a small test and is seems the form.runmodal does not return the modified record if the record is temporary. I guess you will have to completely change your code, or find out an other way to return the new ItemNo to the function. I cannot think of a solution right now, perhaps someone else can. Let me know is nobody responds, maybe I can figure out an other way for you if I have some more time. Regrards, Mark

If you create a global variable in your wizard form assigning the tempitem no. to it in a function to be returned to the calling form, then you can use the following:- IF MyForm.RUNMODAL = ACTION::OK THEN BEGIN NewItemNo := MyForm.ReturnItemNo; SETRANGE("No.",NewItemNo); CurrForm.UPDATE(FALSE); SETRANGE("No."); END; or you can declare a global variable for your new item no. and assign it before calling the wizard:- TempItem.INIT; TempItem."No." := ''; TempItem.INSERT; CLEAR(GlobalItemNo); GlobalItemNo := TempItem."No."; IF FORM.RUNMODAL(FORM::"Create Item",TempItem) = ACTION::OK THEN NewItemNo := GlobalItemNo ELSE NewItemNo := ''; IF NewItemNo <> '' THEN BEGIN SETRANGE("No.",NewItemNo); CURRFORM.UPDATE(FALSE); SETRANGE("No."); END; -Mike