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

Not all operators working

Hello there!

My code gives 0 errors but there is something wrong... there might be ; wrongly placed or too many. Is anyone able to check my code and let me know? 

 

ClearCollect(
    colUrenRegistratie;
    Filter(
        UrenRegistratie;
        Datum = DataCardValue9.Text
        && varcurrentuser = DataCardValue10.Text
    )
);;

Set(
    sumTijdTotaal;
    Sum(
        colUrenRegistratie;
        Text(TijdTotaal)
    )
);;

If(varcurrentuser = "John Stollé";
Set(
    remainder;
    9,75 - Mod(
        Value(sumTijdTotaal);
        9,75
    )
);;

If(Weekday(
    Date(
        Value(Right(DataCardValue9.Text;4));
        Value(Mid(DataCardValue9.Text;4;2));
        Value(Left(DataCardValue9.Text;2))
    )
) = 6 && varcurrentuser <> "John Stollé"; Set(
    remainder;
    7 - Mod(
        Value(sumTijdTotaal);
        7
    )
);; 

Set(
    remainder;
    8 - Mod(
        Value(sumTijdTotaal);
        8
    )
)));;


Set(varTijdTotaal; 
    Value(EditForm1.Updates.TijdTotaal) 
    - remainder
);;


If(
    Value(DataCardValue11.Text) <= remainder;
    SubmitForm(EditForm1);
    
    If(
        !EditForm1.Valid;
        Notify(
            "Een of meer velden zijn niet correct ingevuld.";
            NotificationType.Error
        );
        Patch(
            UrenRegistratie;
            Defaults(UrenRegistratie);
            EditForm1.Updates;
            {TijdTotaal: remainder}
        );;
        Patch(
            UrenRegistratie;
            Defaults(UrenRegistratie);
            EditForm1.Updates;
            {TijdTotaal: varTijdTotaal}
        );;
        ResetForm(EditForm1);;
        Navigate([@Overzicht]; Fade);;
        If(
            !IsEmpty(Errors(UrenRegistratie));
            Notify(
                "Er is een fout bij het versturen van het format, hierdoor zijn niet alle rijen succesvol verzonden.";
                NotificationType.Error
            );;
            ResetForm(EditForm1);;
            Navigate(
                [@Overzicht];
                Fade
            )
        )
    )
)

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

From what I can see your code doesn't check if the total hours is >7 or >8 it is just mod'ing them regardless of how large the total time is. I've also updated the patch to check if the remainder is actually >0, if not then don't patch it as it will be a blank entry?

 

 

ClearCollect(
    colUrenRegistratie;
    Filter(
        UrenRegistratie;
        Datum = 
            DataCardValue9.Text
         And varcurrentuser = Werknemer
    )
);;

Set(
    sumTijdTotaal;
    Sum(
        colUrenRegistratie;
        Text(TijdTotaal)
    )
);;

If(
   //If current use is John
   varcurrentuser = "John Stollé";
   
   //If total is >9.75 then mod otherwise dont mod
   If(
       sumTijdTotaal>9,75;
       Set( remainder; 9,75 - Mod( Value(sumTijdTotaal); 9,75 );
       Set( remainder; 0)

       )
   )
   ;
   //Otherwise if user is not John
   // AND if Weekday is 6
   If(
      Weekday(
         Date(
            Value(Right(DataCardValue9.Text;4));
            Value(Mid(DataCardValue9.Text;4;2));
            Value(Left(DataCardValue9.Text;2))
         )
      ) = 6
      ;
      // then set remainder mod7
      //If total is >7 then mod otherwise dont mod
      If(
         sumTijdTotaal>7;
         Set( remainder; 7 - Mod( Value(sumTijdTotaal); 7 );
         Set( remainder; 0 )
      )
      ;
      //otherwise set remainder mod 8
      //If total is >8 then mod otherwise dont mod
      If(
         sumTijdTotaal>7;
         Set( remainder; 8 - Mod( Value(sumTijdTotaal); 8 );
         Set( remainder; 0 );
   )
);;

Set(varTijdTotaal; 
    sumTijdTotaal - remainder
);;


If(
    Value(DataCardValue11.Text) <= remainder;
    SubmitForm(EditForm1);
    
    If(
        !EditForm1.Valid;
        Notify(
            "Een of meer velden zijn niet correct ingevuld.";
            NotificationType.Error
        );
        //If Remainder is >0 then patch the reaminder otherwise don't create two entries
        If(
           remainder>0;
           Patch(
               UrenRegistratie;
               Defaults(UrenRegistratie);
               EditForm1.Updates;
               {TijdTotaal: remainder}
           )
        );;
        Patch(
            UrenRegistratie;
            Defaults(UrenRegistratie);
            EditForm1.Updates;
            {TijdTotaal: varTijdTotaal}
        );;
        ResetForm(EditForm1);;
        Navigate([@Overzicht]; Fade);;
        If(
            !IsEmpty(Errors(UrenRegistratie));
            Notify(
                "Er is een fout bij het versturen van het format, hierdoor zijn niet alle rijen succesvol verzonden.";
                NotificationType.Error
            );;
            ResetForm(EditForm1);;
            Navigate(
                [@Overzicht];
                Fade
            )
        )
    )
)

 

 


@iAm_ManCat

Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!


Thanks!
You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


View solution in original post

8 REPLIES 8
Highlighted
Super User III
Super User III

@TimoMigchielsen
You said 'something went wrong' with your code.  Could you please let the forums know what went wrong?  It will help us solve your problem.

 

Also, it is a best practice that any code written after the SubmitForm function should go either in the OnSuccess or OnFailure property of the form.

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Highlighted
Super User II
Super User II

I think it's this part:

        Set(
            remainder;
            7 - Mod(
                Value(sumTijdTotaal);
                7
                )
        );; 

        Set(
            remainder;
            8 - Mod(
                Value(sumTijdTotaal);
                8
            )
        )

You're checking if weekday and user <> and if yes then you are doing 7-mod, but then you have a double ;; so you are also doing 8-mod (instead of doing it when not weekday).

 

Also this part:

//if form valid then patch
        Patch(
            UrenRegistratie;
            Defaults(UrenRegistratie);
            EditForm1.Updates;
            {TijdTotaal: remainder}
        );;
        //AND patch this?
        Patch(
            UrenRegistratie;
            Defaults(UrenRegistratie);
            EditForm1.Updates;
            {TijdTotaal: varTijdTotaal}
        );;

You are saying with the ;; that both of these are running one after the other, so when your form is valid it first patches the updates from the form and changes the TijdTotaal value to remainder, then it immediately afterwards patches that same Updates and changes TijdTotaal to varTijdTotaal?

 

Also this bit:

        //Reset form and navigate away
        ResetForm(EditForm1);;
        Navigate([@Overzicht]; Fade);;

        // This point is never reached as it has already reset and navigated!
        If(
            !IsEmpty(Errors(UrenRegistratie));
            Notify(
                "Er is een fout bij het versturen van het format, hierdoor zijn niet alle rijen succesvol verzonden.";
                NotificationType.Error
            );;
            ResetForm(EditForm1);;
            Navigate(
                [@Overzicht];
                Fade
            )
        )

You should move the check for errors up and get rid of the first reset/nav as they will happen anyway if there are no errors.

 

So code should end up something like:

ClearCollect(
    colUrenRegistratie;
    Filter(
        UrenRegistratie;
        Datum = DataCardValue9.Text
        && varcurrentuser = DataCardValue10.Text
    )
);;

Set(
    sumTijdTotaal;
    Sum(
        colUrenRegistratie;
        Text(TijdTotaal)
    )
);;

If(varcurrentuser = "John Stollé";
    Set(
        remainder;
        9,75 - Mod(
            Value(sumTijdTotaal);
            9,75
        )
    );;

    If(
        Weekday(
            Date(
                Value(Right(DataCardValue9.Text;4));
                Value(Mid(DataCardValue9.Text;4;2));
                Value(Left(DataCardValue9.Text;2))
            )
        ) = 6 && varcurrentuser <> "John Stollé"
        ;
        Set(
            remainder;
            7 - Mod(
                Value(sumTijdTotaal);
                7
                )
        );

        Set(
            remainder;
            8 - Mod(
                Value(sumTijdTotaal);
                8
            )
        )
    )
);;


Set(varTijdTotaal; 
    Value(EditForm1.Updates.TijdTotaal) 
    - remainder
);;


If(
    Value(DataCardValue11.Text) <= remainder;
    
    //Then submit
    SubmitForm(EditForm1);
    
    //Otherwise do:
    If(
        //If form is not valid then notify
        !EditForm1.Valid;
        Notify(
            "Een of meer velden zijn niet correct ingevuld.";
            NotificationType.Error
        );
        
        ///////////////////////////////////
        //
        // Not sure what to do here, but 
        // having two of the same patch run 
        // seems counterintuitive
        //
        // If form valid then patch
        Patch(
            UrenRegistratie;
            Defaults(UrenRegistratie);
            EditForm1.Updates;
            {TijdTotaal: remainder}
        );;
        // AND patch this?
        Patch(
            UrenRegistratie;
            Defaults(UrenRegistratie);
            EditForm1.Updates;
            {TijdTotaal: varTijdTotaal}
        );;
        If(
            !IsEmpty(Errors(UrenRegistratie));
            Notify(
                "Er is een fout bij het versturen van het format, hierdoor zijn niet alle rijen succesvol verzonden.";
                NotificationType.Error
            );;
            ResetForm(EditForm1);;
            Navigate(
                [@Overzicht];
                Fade
            )
        )        
    )
)

 

Not sure if that will work as there's still an issue with the two patches, but its a step in the right direction I think


@iAm_ManCat

Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!


Thanks!
You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


Highlighted

Thank you for your answers. @iAm_ManCat @mdevaney 

It was working last week so I just went back to another version, what fixed it. The part of the patch was correct, it needs to patch it twice 😄


Highlighted

@TimoMigchielsen 

If you found a solution please accept an answer.  Otherwise people will think your forums question is still not solved.

Highlighted

Hello there! There is something strange going on with my app. On the start of my application I have the following code to get their full name of Office. 

Set(
    varcurrentuser; 
    User().FullName
);;

Whenever they fill in a ticket, their fullname is saved in a column named "Werknemer". The code down below makes a collection of the users worked hours on the date they filled in a textbox. If the TijdTotaal is higher than 8 it creates an extra ticket with the remaining hours. Whenever it is friday, this is being done after 7 hours instead of 8. Whenever John Stolle logs in, it will be after 9,75 hours. Whenever I fill in the ticket, it works completely fine. Whenever another customer fills in the tickets, the following happends; He makes a ticket with 1 hour, this ticket already gets split up into 2 tickets somehow. He later creates another ticket with 8,5 hours and this one also get splitted. This is what was supposed to happen; 28/09/2020 was a on monday so the ticket should have been split after 8 hours.

He creates a ticket with 1 hour, the ticket gets submitted. He then creates a ticket with 8,5 hours. This ticket gets split up. Since the first ticket was 1 hour, the second one should be 7 hours and then the third ticket will be the remaining hours, 1,5 hours. This is working for me fine, but not for the other user. What could be causing this to happen? @mdevaney @iAm_ManCat 

Database; https://gyazo.com/fd7332a46e141754a0cbfa1be162730f

ClearCollect(
    colUrenRegistratie;
    Filter(
        UrenRegistratie;
        Datum = 
            DataCardValue9.Text
         And varcurrentuser = Werknemer
    )
);;

Set(
    sumTijdTotaal;
    Sum(
        colUrenRegistratie;
        Text(TijdTotaal)
    )
);;

If(varcurrentuser = "John Stollé";
Set(
    remainder;
    9,75 - Mod(
        Value(sumTijdTotaal);
        9,75
    )
);

If(Weekday(
    Date(
        Value(Right(DataCardValue9.Text;4));
        Value(Mid(DataCardValue9.Text;4;2));
        Value(Left(DataCardValue9.Text;2))
    )
) = 6 && varcurrentuser <> "John Stollé"; Set(
    remainder;
    7 - Mod(
        Value(sumTijdTotaal);
        7
    )
);;; Set(
    remainder;
    8 - Mod(
        Value(sumTijdTotaal);
        8
    )
)));;


Set(varTijdTotaal; 
    Value(EditForm1.Updates.TijdTotaal) 
    - remainder
);;


If(
    Value(DataCardValue11.Text) <= remainder;
    SubmitForm(EditForm1);
    
    If(
        !EditForm1.Valid;
        Notify(
            "Een of meer velden zijn niet correct ingevuld.";
            NotificationType.Error
        );
        Patch(
            UrenRegistratie;
            Defaults(UrenRegistratie);
            EditForm1.Updates;
            {TijdTotaal: remainder}
        );;
        Patch(
            UrenRegistratie;
            Defaults(UrenRegistratie);
            EditForm1.Updates;
            {TijdTotaal: varTijdTotaal}
        );;
        ResetForm(EditForm1);;
        Navigate([@Overzicht]; Fade);;
        If(
            !IsEmpty(Errors(UrenRegistratie));
            Notify(
                "Er is een fout bij het versturen van het format, hierdoor zijn niet alle rijen succesvol verzonden.";
                NotificationType.Error
            );;
            ResetForm(EditForm1);;
            Navigate(
                [@Overzicht];
                Fade
            )
        )
    )
)

 

Highlighted

From what I can see your code doesn't check if the total hours is >7 or >8 it is just mod'ing them regardless of how large the total time is. I've also updated the patch to check if the remainder is actually >0, if not then don't patch it as it will be a blank entry?

 

 

ClearCollect(
    colUrenRegistratie;
    Filter(
        UrenRegistratie;
        Datum = 
            DataCardValue9.Text
         And varcurrentuser = Werknemer
    )
);;

Set(
    sumTijdTotaal;
    Sum(
        colUrenRegistratie;
        Text(TijdTotaal)
    )
);;

If(
   //If current use is John
   varcurrentuser = "John Stollé";
   
   //If total is >9.75 then mod otherwise dont mod
   If(
       sumTijdTotaal>9,75;
       Set( remainder; 9,75 - Mod( Value(sumTijdTotaal); 9,75 );
       Set( remainder; 0)

       )
   )
   ;
   //Otherwise if user is not John
   // AND if Weekday is 6
   If(
      Weekday(
         Date(
            Value(Right(DataCardValue9.Text;4));
            Value(Mid(DataCardValue9.Text;4;2));
            Value(Left(DataCardValue9.Text;2))
         )
      ) = 6
      ;
      // then set remainder mod7
      //If total is >7 then mod otherwise dont mod
      If(
         sumTijdTotaal>7;
         Set( remainder; 7 - Mod( Value(sumTijdTotaal); 7 );
         Set( remainder; 0 )
      )
      ;
      //otherwise set remainder mod 8
      //If total is >8 then mod otherwise dont mod
      If(
         sumTijdTotaal>7;
         Set( remainder; 8 - Mod( Value(sumTijdTotaal); 8 );
         Set( remainder; 0 );
   )
);;

Set(varTijdTotaal; 
    sumTijdTotaal - remainder
);;


If(
    Value(DataCardValue11.Text) <= remainder;
    SubmitForm(EditForm1);
    
    If(
        !EditForm1.Valid;
        Notify(
            "Een of meer velden zijn niet correct ingevuld.";
            NotificationType.Error
        );
        //If Remainder is >0 then patch the reaminder otherwise don't create two entries
        If(
           remainder>0;
           Patch(
               UrenRegistratie;
               Defaults(UrenRegistratie);
               EditForm1.Updates;
               {TijdTotaal: remainder}
           )
        );;
        Patch(
            UrenRegistratie;
            Defaults(UrenRegistratie);
            EditForm1.Updates;
            {TijdTotaal: varTijdTotaal}
        );;
        ResetForm(EditForm1);;
        Navigate([@Overzicht]; Fade);;
        If(
            !IsEmpty(Errors(UrenRegistratie));
            Notify(
                "Er is een fout bij het versturen van het format, hierdoor zijn niet alle rijen succesvol verzonden.";
                NotificationType.Error
            );;
            ResetForm(EditForm1);;
            Navigate(
                [@Overzicht];
                Fade
            )
        )
    )
)

 

 


@iAm_ManCat

Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!


Thanks!
You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


View solution in original post

Highlighted

Thank you for your fast answer, I really appreciate that! @iAm_ManCat 

We still need to check what user is logged in. That's what the collection was for. If for example I have 2 employees. Named Timo and Peter. 

If Timo submits a ticket of 4 hours on the date of the value of 

DataCardValue9.Text

 This is a date value. For example 29/09/2020. 

If Peter then submits a ticket of 5 hours. It should not be split up. It needs to look if the current user has a total of 8 hours on the dayvalue of 

DataCardValue9.Text

 Hope I explained this clear enough. 

Highlighted

Hi,

 

Sorry, I wasn't saying to remove the code above that If( - that code is fine, I was just focusing on the code below, I update my previous post.

 

Cheers,

Sancho


@iAm_ManCat

Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!


Thanks!
You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (12,455)