cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
TimoMigchielsen
Post Prodigy
Post Prodigy

submitting 2 forms if total hours = over 8

Hello!

I am having a ticket system where workers can clock-in during their worktime. The app looks like this: https://gyazo.com/c8761eaa962db09ceb8dff502ba24321


Database looks like this:
https://gyazo.com/bccfff0f750091f347877325f6d67d82
Whenever the column tijdtotaal of the day they are wanting to fill in a ticket, is higher than 8, I want it to make a new ticket with the rest of the hours. 

This is what we need to do: 

-Everytime a new ticket gets created, we need to filter the database on the date of today and see how many rows are there. It then needs to check if TijdTotaal is over 8. When it is over 8, I want it to match up exactly to 8. This may be confusing so I will explain it with a screenshot.

How it is now: https://gyazo.com/b979d3d96597e7eeb8a351dfd4b8a433
How it should look like: https://gyazo.com/f256e7f855acaf9419592bae5bbbe3ff

It needs to calculate it to 8 and use the rest of the time to make a new ticket with the same information as the last ticket. How can we get this?

Just using this code to send the form away: SubmitForm(EditForm1)



I hope I have explained this well enough, if I didn't, let me know and I will try and explain it better. 

Code we have tried right now: 

 

 

ClearCollect(colUrenRegistratie, Filter(
        UrenRegistratie,
        Datum = Text(
            Today (),
            "dd/mm/yyyyy"
        ) And varcurrentuser = Werknemer
    ));

With(
    {
        sumTijdTotaal: Sum(colUrenRegistratie,TijdTotaal)
    },
    With(
        {
            remainder: 8-Mod(sumTijdTotaal,8)
        },
        If(
            EditForm1.Updates.TijdTotaal<=8,
            SubmitForm(EditForm1),
            If( 
                !EditForm1.Valid,
                Notify("One or more fields in the form were not entered correctly.",NotificationType.Error),
                Patch(UrenRegistratie,Defaults(UrenRegistratie),EditForm1.Updates,{TijdTotaal: remainder});
                Patch(UrenRegistratie,Defaults(UrenRegistratie),EditForm1.Updates,{TijdTotaal: EditForm1.Updates.TijdTotaal-remainder});

                If(
                    !IsEmpty(Errors(UrenRegistratie)),

                    Notify("There was an error submitting the form and records may not have been submitted successfully.",NotificationType.Error);
                    ResetForm(EditForm1);
                    Navigate([@Overzicht],Fade)
                )
            )
        )
    )
)

 

5 REPLIES 5
jlindstrom
Super User
Super User

So when a record is entered you want to submit another form? That is a lot of code for a low code app. I would offload the process go power automate and on create or update of the first record, have flow evaluate the dat submitted and if less than 8 hours roll it up to 8

Hello @jlindstrom,

Thank you for your answer. The app needs to do way more than that. 

If a ticket gets created thats over 8 hours, it needs to split it up. Let's say I make a ticket of 9 hours, it should split them up. 

The first one would have 8 hours, second ticket would have 1 hour. 

And then another one gets created with 8 hours, it will needs to get split again, first one has to be 7 hours (1 from the last ticket + 7 to make it 😎 

Second ticket then gets 1 hour, the remainder. It would be helpfull to read all of the explanations above. 

So you have two general options: client side (build it into the app) or server side (use power automate)

 

you can make your solution do way more than what you describe, my advice is be strategic about how you do it so you provide a performance experience.

 

 

If you are querying the database and splitting things up you probably want to move to patch rather then submit form.


the reason I recommend patch vs submit form is because it allows you a lot more control, where submit simply saves the record.

 

see mr Dangs video for more details https://youtu.be/IIzgkdu0Uxs

 

and if you need bulk data operations such as splitting up existing records, that should typically be done as a background process

 

How would you do the full code then? @jlindstrom 

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (89,113)