web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Context variable form ...
Power Apps
Answered

Context variable form (Mr-Dang solution)

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hello,

 

I'm trying to use an adapted version of the solution originally posted by Mr-Dang here: https://powerusers.microsoft.com/t5/PowerApps-Forum/Patch-Timestamp/m-p/30311/highlight/true#M12775

 

 

However I am using the above to allow a user to log in and then submit information to a sharepoint list via a form in the app. The user logs in, fills out some of the form and clicks start job. Later, once the user has finished, the user returns to the app, fills out the remaining fields on the form and clicks end job.

 

I can use the solution above as long as there is only one person per device. However it does not work if one person starts a job and then a second person does the same as the context variable is overwritten. I wonder if there is a way to store the form information in the context variable and have one row per person. The idea being that when person logs in again, the form reloads their information from the contaxt variable.

 

In an ideal world a person could start a job from one device and then finish it in another (eg patch the context variable to the database and then reload it again next time that specific user logs in if it was not finished).

 

Any ideas?

Categories:
I have the same question (0)
  • v-micsh-msft Profile Picture
    Microsoft Employee on at

    Hi @Anonymous,

     

    I think here you means to keep the record offline.

    I will make some tests on this, and update here later.

    Share a blog for reference:

    https://powerapps.microsoft.com/en-us/blog/build-offline-apps-with-new-powerapps-capabilities/

     

    Regards,

    Michael

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @v-micsh-msft

     

    Thank you for helping with this - we are creating a feedback app internally for workers and wish to see how long they spend on each job. The problem is that they might start a job on one device, spend the whole day on it, and then finish the job from another device.

     

    I hope that makes sense. I have tried patching to the sharepoint list but I am falling over on how to recall the correct records!

     

    Thanks 🙂

  • v-micsh-msft Profile Picture
    Microsoft Employee on at

    Hi @Anonymous,

     

    Post back to share some feedback.

    I thought keeping the record offline may work with your scenario, but it requires the data stored within the same device.

    If the user may work under different device, then we should keep the record with an online data source, and use filter to locate the corresponding record.

    To better understand your scenario, could you please share more details, for example, the data source, like SharePoint List (corresponding columns), sign-in table information, and the App controls you used?

    Here are a few thoughs based on the current information:

    1. There is a sign-in table, used to check user sign-in and sign out, a data table, in SharePoint list, woking with form control,

    2. User signs in with a check under the sign-in table, if no record for a specific time and the sign-in field is empty, switch form control to New mode,

    3. Two buttons to work with Start job and end job, for Start, create a new item under SharePoint list, recording the Start time, with submitForm() function, once clicked, disable the Start Button itself,switch the form control in Edit mode,

    4. Here we have two tables containing the user information, and comes to the part to recall the record, 

      Two conditions:

      a. User didn't sign out, two ways to recall the submitted record, Form.LastSubmit, or Frist(filter(table, conditions)), here we use the second one, as the lastsubmit may vary for different users, 

      b. User signed out, we need to get back the status, so here we should configure the Onvisible property of the landing screen, checking with the two tables to get back the information, using some variable to update form control mode and the button status,

    5. If step 4 has been well configured, then here we need to end the job, as the record has already been created, here we use patch to update the corresponding record, 

     

    Regards,

    Michael

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi Michael,

     

    Thank you very much for coming back to me, your solution should work perfectly, but I'm afraid I will need a little help implementing.

     

    All asumptions are correct. There are two lists in sharepoint, one containing usernames and passwords (Production_Users), another containing the information captured in the form (Production_Database). Currently, the 'login' button has an onvisible property with a lookup matching the password with the username. The onselect property is NewForm() & Navigate().

     

    1. Currently no reporting of login/logout times, only job start/end times. I could certainly add a column for logged in - true/false.

    2. Clever idea - I will look to implement this using Patch().

    3. Again a clever idea - how do i switch the active form on the screen to an Edit from New? A combination of SubmitForm() & EditForm(filters to find the correct one)?

    4. Agreed, can filter  on first(this is the function that mr-dang used, i will need to properly familerise myself with it.

    5. Confused here why you would use patch and not submit the edited form? Is it so that you don't overwrite the job start time? If using patch, do I have to include every field in the form in the argument?

     

    To make the above easier, I'm going to add a screen inbetween login and the job info which will show any of the users open jobs in a gallery and then a button for new job.

     

    Thanks again for spending time thinking about this Michael, it is very much apreciated.

     

    Max

  • Verified answer
    v-micsh-msft Profile Picture
    Microsoft Employee on at

    Hi @Anonymous,

     

    For form mode switch, consider take use of a variable with the updatecontext() function.

     

    For option 5, yes, using the submitform() function should also work. Consideration here is that when the whole form is under Edit mode, all the fields would be in Edit mode, some fields (as you mentioned, the StartTime )might be changed, if all the fields are editable, then that's OK to switch to SubmitForm() function.

     

    For all the fields, no, there is no need to add all the fields, 

    Patch(table, EditRecord, {Fields})

    Here we will use the submitted record as the second parameter of the patch, which should be able for patch to match the corresponding record, for the fields, only add the part needed for ending the job.

    That is assuming all the fields could be divided into start, or End related.

    Regards,

    Michael

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi Micahel,

     

    I really appreciate your help with this one - I'm almost there. I've managed to setup the use of context variables to let the form know whether to edit the selected item from the gallery or to start a new form, and when the jobs started which form to select (using lastsubmitted).

     

    On the Patch() front, I have used an alternative method. The issue is that every time we add a new field to the form I will have to remember to update the patch formula to include it.

     

    Instead what I have done is create a context variable titled 'JobRunning' (set to false by default on new jobs) which is set to true as part of the onselect property of the first submit, Job Start, button (sending jobstart related information to the sharepoint table). As JobRunning is set to 'true' all the job end related fields switch from default.Blank() to their correct default values.

     

    I would like to thank you very much for your help on this Michael. It seemed like such a big problem at the start but with your help has been broken down into digestible steps.

     

    Best,

     

    Max

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 633

#2
11manish Profile Picture

11manish 588

#3
Valantis Profile Picture

Valantis 457

Last 30 days Overall leaderboard