cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sasrsc
Resolver II
Resolver II

DRY - I have to perform some quality control checks on the data in my app in a few different places...

There will in the end be about 20-30 checks....

Below is some sample code....and the last half is taken up with the beginning of working through this.
Ultimately I intend to collapse the conditional checks into 5 variables...
isAirError
isAirInError
isAirOutError
isHotelError
isQCError (which is "true" if any of the other 4 things are true)

Each of the above variables will go through 5 or so checks and then render true or false...

For example:
for the hotel...
If the hotelRequest is empty then true,
If the hotelRequest is "No" and a hotel is booked then true,
If the hotelCheckIn date doesn't match the airArrivalDate then true, etc...
and it continues... 
Ideally I want 2 things...
1) To display a gallery of the individual checks completed and the pass/fail. It would list show a description and then likely a red or green circle to indicate a pass or fail. That would seem when viewing an individual "record".
2) On a summary screen simply show the "text" value of any errors as a tooltip...where it lists a gallery of records. So it won't take up real estate with this one.

The problem is this is happening on different screens and therefore I believe I need to type out the conditional checks twice which increases the possibility of error, etc...

Has anyone done anything like this and have suggestions of how to make the code more flexible and avoiding DRY. I had even wondered about putting these ~20 conditional statements in a SP Lists and simply referring to the sharepoint list. 

Thoughts/Tips....

 

ClearCollect(
    WorkloadSnapshot,
    AddColumns(
        AddColumns(
            ForAll(
                Attendees As _Att,
                With(
                    {
                        _EventHotels: LookUp(
                            EventHotels,
                            Email = _Att.Email || If(
                                !IsBlank(WorkerNo) && WorkerNo <> "Guest",
                                WorkerNo = _Att.SourceId
                            ) || (Trim(Upper(LastName)) in _Att.'Last Name' && Trim(Upper(FirstName)) in _Att.'First Name')
                        ),
                        _EventFlightsDep: LookUp(
                            EventFlightsDep As _departs,
                            _departs.Email = _Att.Email || If(
                                !IsBlank(_departs.WorkerNo) && _departs.WorkerNo <> "Guest",
                                _departs.WorkerNo = _Att.SourceId
                            ) || (Trim(Upper(_departs.LastName)) in _Att.'Last Name' && Trim(Upper(_departs.FirstName)) in _Att.'First Name')
                        ),
                        _EventFlightsArr: LookUp(
                            EventFlightsArr As _arrives,
                            _arrives.Email = _Att.Email || If(
                                !IsBlank(_arrives.WorkerNo) && _arrives.WorkerNo <> "Guest",
                                _arrives.WorkerNo = _Att.SourceId
                            ) || (Trim(Upper(_arrives.LastName)) in _Att.'Last Name' && Trim(Upper(_arrives.FirstName)) in _Att.'First Name')
                        )
                    },
                    Patch(
                        _Att,
                        {
                            HotelMinCheckIn: _EventHotels.MinCheckIn,
                            HotelMaxCheckOut: _EventHotels.MaxCheckOut,
                            HotelNtsBooked: _EventHotels.NtsBooked,
                            HotelNtsExpected: _EventHotels.NtsExpected,
                            HotelBookings: _EventHotels.Bookings,
                            FlightArrivalDate: _EventFlightsArr.FlightArrivalDate,
                            FlightDepartDate: _EventFlightsDep.FlightDepartDate
                        }
                    )// end of patch
                )// end of with
            ),// end of forall
        /* add remaining columns for the gallery to better function */
            "isHotelError",
            If(
                HotelReq = "Y" && IsEmpty(HotelBookings) || HotelReq = "N" && !IsEmpty(HotelBookings) || If(
                    !IsBlank(FlightArrivalDate) && !IsBlank(HotelMinCheckIn),
                    DateDiff(
                        DateTimeValue(
                            Text(
                                FlightArrivalDate,
                                "[$-en-US]mm/dd/yyyy"
                            )
                        ),
                        DateTimeValue(
                            Text(HotelMinCheckIn,"[$-en-US]mm/dd/yyyy")),
                        Days
                    ) <> 0
                ) || IsBlank(HotelReq),
                true,
                false
            ),
            "isAirError",
            false,
            "isAirInError",
            If(
                ((AirIn = "C" || AirIn = "J") && IsBlank(FlightArrivalDate)) || ((AirIn <> "C" && AirIn <> "J") && !IsBlank(FlightArrivalDate)) || If(
                    !IsBlank(FlightArrivalDate),
                    DateDiff(
                        DateTimeValue(
                            Text(
                                FlightArrivalDate,
                                "[$-en-US]mm/dd/yyyy"
                            )
                        ),
                        Start,
                        Days
                    ) <> 0
                ) || (AirReq = "Y" && IsBlank(FlightArrivalDate) && IsBlank(FlightDepartDate)),
                true,
                false
            ),
            "isAirOutError",
            If(
                ((AirOut = "C" || AirOut = "J") && IsBlank(FlightDepartDate)) || ((AirOut <> "C" && AirOut <> "J") && !IsBlank(FlightDepartDate)) || If(
                    !IsBlank(FlightDepartDate),
                    DateDiff(
                        DateTimeValue(
                            Text(
                                FlightDepartDate,
                                "[$-en-US]mm/dd/yyyy"
                            )
                        ),
                        End,
                        Days
                    ) <> 0
                ) || (AirReq = "Y" && IsBlank(FlightDepartDate) && IsBlank(FlightDepartDate)),
                true,
                false
            )
        ),
        "isQcError",
        If(
            isHotelError = true || isAirError = true || isAirInError = true || isAirOutError = true,
            true,
            false
        )
    )
);

 

0 REPLIES 0

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

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