cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
kevinK
Regular Visitor

Generate ID on New Form without using SubmitForm

I have a form connected to a sharepoint list. The form has a button to open a new screen where I can add tasks. The new screen has a form called TaskForm. When that button is clicked, I set a variable and open the TaskForm, that has item set to this variable.

 

On the TaskForm, there is a field called RefID, which is a helper field that is used to associate with the main record ID.

 

So the Default field of RefID states:

 

if(TaskForm.mode = FormMode.New, variable.ID, ThisItem.RefID)

 

... This works for existing records (i.e. if Record #1 from the main form has 2 tasks, they both appear on the TaskScreen because RefID = 1 for both of the tasks). 

 

The problem is when I create a new record (from the main form), it doesn't assign the ID (i.e. Record #2) until I SubmitForm. The main form has OnSuccess set to Navigate back to the main menu. If I insert a SubmitForm when the TaskScreen is opened, it takes me back to the main menu. I could remove the OnSuccess (set to false), but then I lose the functionality of checking if the form is OK before submitting.

 

Is there another way to assign the ID without using SubmitForm? Or is there a way to use a formula to set OnSuccess only when I click the submit button?

5 REPLIES 5
WarrenBelz
Super User
Super User

Hi @kevinK ,

Firstly, you will not get an ID without creating a new record (SubmitForm in your case). You can find out what it might be

First(
   Sort(
      SPListName,
      ID,
      Descending
   )
).ID + 1

but you would need to run this immediately before creating the record as two users querying it at the same time (or closely apart) will get the same number.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

kevinK
Regular Visitor

Thanks - I thought of that, but don't want to risk the overlap of simultaneous users.

 

Is it possible to prompt the user OnSuccess to say "Do you want to continue editing? Or return to the main form?"... if they click continue editing, OnSuccess would be false, and if they click return to the main form, it would navigate as currently set. Not sure if I can ask OnSuccess to open a new screen and wait for the user to answer...

@kevinK ,

Just do a pop-up with the Visible on a Variable set to true OnSuccess and a couple of buttons, both of which would set the Variable to false and then navigate to the chosen screen.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

kevinK
Regular Visitor

Sorry, I'm not understanding...

 

Can I SubmitForm with the OnVisible property of the screen, and in the OnSuccess of the form do the popup? 

 

My Data Items for the form is set to MenuGallery.Selected. The MenuGallery is on the main screen, and the user selects the record that they want to edit. OnSelect from the main screen, it does this:

 

ClearCollect(colImages, ThisItem.Attachments);

Set(varMainMenuIcon, ThisItem);

ResetForm(EntryForm);

EditForm(EntryForm);

Navigate(EntroFormScreen,Fade);

 

If I SubmitForm(EntryForm) when it is FormMode.New, it displays information from the last record that was selected in the MenuGallery. Do I need to clear the MenuGallery.Selected (somehow?) before SubmitForm?

@kevinK ,

Your structure probably needs looking at. I will suggest something for you to think about - all of my apps use a Global Variable gblID which is set to the ID of the record being currently actioned. For instance, at Gallery OnSelect I have

Set(
   gblID,
   ThisItem.ID
)

 The Item of a Form showing the record

LookUp(
   ListName,
   ID = gblID
)

OnSuccess of the form

Set(
   gblID,
   Self.LastSubmit.ID
)

It does not matter if it is already this value on Edit forms - when the Form is submitted in New mode. it will update to the record just created.

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Power Apps Ideas

Changes to Ideas Coming

We are excited to announce a new way to share your ideas for Power Apps!

Top Solution Authors
Top Kudoed Authors
Users online (2,927)