RunFormMode Question - Trigger Edit/Create Accordingly?

Hey guys,

Ran into a bit of a snag, and I’m hoping there’s an easy way to fix this using C/AL code or some other method. Right now I have a page that opens in Edit mode, which allows us to view and modify the current record. I have it intelligently pick the row of data to modify, since there should only be one per item record (the table I created it a subset of item, if that makes sense)

The problem is that if we don’t have a row already created with that item number, it opens in a read-only state and won’t let us input data. Unlike in the Classic client, using a form, the only way I can see to fix this is to do Action - New, then save it, then go back to the edit page. I tried setting the default view to Create, but the problem then is that you cannot edit data from that page once it’s been inserted, it’ll always try to insert duplicate lines.

Basically, I am looking for a way to have the page open in Edit mode by default, but that if there is no record to edit - change the view to create mode. As soon as the user clicks OK to close the page, if they open that page again from the actions menu, it’ll open in edit mode (like I set it to from Page Actions), and they’ll be able to see the data they previously entered.

It seems pretty straightforward, basically I want an “insert/update view”, but I can’t find any options in NAV to do that.

Hi Danny,

This sounds a lot like your “Lock Forms to One Object” question, and I think that Erik’s suggestion that you modify the code in your Action trigger to insert a record if one doesn’t already exist would serve you well in this case also.

You can approach this from the parent page in which you created the Action that opens your edit page, or you can work directly in the edit page.

Working from the parent page that includes your custom Action … You mentioned that you “have it intelligently pick the row of data to modify.” If that’s done through properties in the Action control, you may need to build a function instead. If you’re already using code to do this, then you’re almost home. Your goal is to inspect the filtered recordset just before you open the edit page and, if the recordset is empty, insert a blank record with the necessary primary key values. Presumably this would change the record count in your filtered recordset to 1 from 0, and would allow the edit page to open in edit mode.

Or, you could work directly in the edit page, in the OnOpenPage trigger. Here too you would inspect the recordset to determine whether it is empty and, if so, you would take a look at the filter settings on the primary key fields, initialize a new record, assign the primary key field values from the filters set on those fields, and then insert the record.

Both ways should work, so it’s just up to you as to which method works best for you.

Hope that helps.

It’s worth pointing out that what you’re doing here (splitting a very big record into two or more sibling records to work around size limitations imposed by the NAV architecture) is not something that’s never been done, but it’s also not something that the NAV development environment is well suited for. That doesn’t mean that it can’t be done, only that it will take a good bit of work to accomplish tasks that would otherwise be very straightforward.

Yes, I am doing it through the actions menu.

Really, all I did was on the item page, add a promoted action that runs the page I want, with a RunFormLink of Item No.=FIELD(No.).

That’s also where I put RunFormMode as Edit.

I am certainly willing to use functions/code to so this, I just don’t know much about it so I’d need someone to help me out.

Believe it or not, your license may play a role in designing this function. Before we get too far along, let’s determine whether you can see the code behind the Action control. To check, open the page in Object Designer, open the Action list, locate you custom Action and press F9 (or click View | C/AL Code). Let me know whether that takes you to the OnAction trigger for the Action control.

And, you may want to start with a new Action control instead of trying to edit the existing one. I think it’s cleaner, and much easier to just delete the original after you’ve finished testing the new one.

Let me know whether you can see that trigger in the C/AL Editor.