powerapps offline capability

 Save button:

If(
    Connection.Connected,
    If(
        FormModeIs = "New",
        Patch(
            'Spill Reporting',
            Defaults('Spill Reporting'),
            {
                Division: Division_DataCardValue.Text,
                District: District_DataCardValue.Text,
                Facility: Facility_DataCardValue.Text,
                State: State_DataCardValue.Text,
                County: County_DataCardValue.Text,
                'Date/Time of Discovery': DateValue_DateTimeDiscovery.SelectedDate + Time(
                    Value(HourValue_DateTimeDiscovery.Selected.Value),
                    Value(MinuteValue_DateTimeDiscovery.Selected.Value),
                    Value("00")
                ),
                'Date/Time Reported to HSE': DateValue_DateTimeHSE.SelectedDate + Time(
                    Value(HourValue_HSEHours.Selected.Value),
                    Value(MinuteValue_HSEMin.Selected.Value),
                    Value("00")
                ),
                Pipeline: DataCardValue_Pipeline.Text,
                'Quantity of Release': DataCardValue_QuantityOfRelease.Text,
                'Short Description of Release ': DataCardValue_ShortDesRelease.Text,
                'Latitude/Longitude': DataCardValue_LatLong.Text,
                'NRC Reportable': DataCardValue_NRCReportable.Value,
                'NRC Reportable justification statement': DataCardValue_NRCRepJust.Text,
                'T-State Reportable': DataCardValue_StateReportable.Value,
                'T-State Justification': DataCardValue_StateRepJust.Text,
                'PHMSA 30-Day Reportable': DataCardValue_PHMSAYesNo.Value,
                'PHMSA 30-Day reportable justification statement)': DataCardValue_PHMSAStatement.Text,
                'State Reportable': DataCardValue_PHMSA_StateReport.Value,
                'State Reportable justification statement': DataCardValue_PHMSA_StateRepJust.Text
            }
        );
        Notify(
            "Saved Successfully",
            Success,
            5000
        );
        Clear(ColDivisionSelectedValues);
        Clear(ColDistrictSelectedValues);
        Clear(ColFacilitySelectedValues);
        Clear(ColStateSelectedValues);
        Clear(ColCountySelectedValues);
        Clear(ColDistrictSelectedValues1a);
        Clear(ColFacilitySelectedValues1a);
        Clear(ColCountySelectedValues1a);
        Set(ResetNewForm, true);
        Navigate(SuccessScreen);
    );
    If(
        FormModeIs = "Edit",
        Patch(
            'Spill Reporting',
            LookUp(
                'Spill Reporting',
                ID = Gallery1.Selected.ID
            ),
            {
                Division: Division_DataCardValue.Text,
                District: District_DataCardValue.Text,
                Facility: Facility_DataCardValue.Text,
                State: State_DataCardValue.Text,
                County: County_DataCardValue.Text,
                'Date/Time of Discovery': DateValue_DateTimeDiscovery.SelectedDate + Time(
                    Value(HourValue_DateTimeDiscovery.Selected.Value),
                    Value(MinuteValue_DateTimeDiscovery.Selected.Value),
                    Value("00")
                ),
                'Date/Time Reported to HSE': DateValue_DateTimeHSE.SelectedDate + Time(
                    Value(HourValue_HSEHours.Selected.Value),
                    Value(MinuteValue_HSEMin.Selected.Value),
                    Value("00")
                ),
                Pipeline: DataCardValue_Pipeline.Text,
                'Quantity of Release': DataCardValue_QuantityOfRelease.Text,
                'Short Description of Release ': DataCardValue_ShortDesRelease.Text,
                'Latitude/Longitude': DataCardValue_LatLong.Text,
                'NRC Reportable': DataCardValue_NRCReportable.Value,
                'NRC Reportable justification statement': DataCardValue_NRCRepJust.Text,
                'T-State Reportable': DataCardValue_StateReportable.Value,
                'T-State Justification': DataCardValue_StateRepJust.Text,
                'PHMSA 30-Day Reportable': DataCardValue_PHMSAYesNo.Value,
                'PHMSA 30-Day reportable justification statement)': DataCardValue_PHMSAStatement.Text,
                'State Reportable': DataCardValue_PHMSA_StateReport.Value,
                'State Reportable justification statement': DataCardValue_PHMSA_StateRepJust.Text
            }
        );
        Notify(
            "Updated the Item ID " & Gallery1.Selected.ID & " Successfully",
            Success,
            5000
        );
        Clear(ColDivisionSelectedValues);
        Clear(ColDistrictSelectedValues);
        Clear(ColFacilitySelectedValues);
        Clear(ColStateSelectedValues);
        Clear(ColCountySelectedValues);
        Clear(ColDistrictSelectedValues1a);
        Clear(ColFacilitySelectedValues1a);
        Clear(ColCountySelectedValues1a);
        Set(ResetNewForm, true);
        Navigate(SuccessScreen);
    );
    ,
    //Offline
    Collect(
        MyItemsToPost,
        {
            Division: Division_DataCardValue.Text,
            District: District_DataCardValue.Text,
            Facility: Facility_DataCardValue.Text,
            State: State_DataCardValue.Text,
            County: County_DataCardValue.Text,
            'Date/Time of Discovery': DateValue_DateTimeDiscovery.SelectedDate + Time(
                Value(HourValue_DateTimeDiscovery.Selected.Value),
                Value(MinuteValue_DateTimeDiscovery.Selected.Value),
                Value("00")
            ),
            'Date/Time Reported to HSE': DateValue_DateTimeHSE.SelectedDate + Time(
                Value(HourValue_HSEHours.Selected.Value),
                Value(MinuteValue_HSEMin.Selected.Value),
                Value("00")
            ),
            Pipeline: DataCardValue_Pipeline.Text,
            'Quantity of Release': DataCardValue_QuantityOfRelease.Text,
            'Short Description of Release ': DataCardValue_ShortDesRelease.Text,
            'Latitude/Longitude': DataCardValue_LatLong.Text,
            'NRC Reportable': DataCardValue_NRCReportable.Value,
            'NRC Reportable justification statement': DataCardValue_NRCRepJust.Text,
            'T-State Reportable': DataCardValue_StateReportable.Value,
            'T-State Justification': DataCardValue_StateRepJust.Text,
            'PHMSA 30-Day Reportable': DataCardValue_PHMSAYesNo.Value,
            'PHMSA 30-Day reportable justification statement)': DataCardValue_PHMSAStatement.Text,
            'State Reportable': DataCardValue_PHMSA_StateReport.Value,
            'State Reportable justification statement': DataCardValue_PHMSA_StateRepJust.Text,
            FormModeValueIs:FormModeIs
        }
    );
    Notify("Since you are in Offline, Your submission has saved under cache. Once you are in Online, Your submission will automatically update to the data source. Thank you!",NotificationType.Information,10000);
    SaveData(
        MyItemsToPost,
        "MyItemsToPost"
    );
    Clear(ColDivisionSelectedValues);
    Clear(ColDistrictSelectedValues);
    Clear(ColFacilitySelectedValues);
    Clear(ColStateSelectedValues);
    Clear(ColCountySelectedValues);
    Clear(ColDistrictSelectedValues1a);
    Clear(ColFacilitySelectedValues1a);
    Clear(ColCountySelectedValues1a);
    Set(ResetNewForm, true);
    Navigate(DetailsScreen);
);
------------------------------------------------------------------------

App OnStart

Clear(ColDivisionDropdown);Clear(ColDistrictDropdown);Clear(ColFacilityDropdown);Clear(ColStateDropdown);Clear(ColCountyDropdown);


Collect(ColDivisionDropdown, ShowColumns(Filter(MaximoDivision, Status = "ACTIVE"),"Title"));

Collect(ColDistrictDropdown,ShowColumns(Filter(MaximoDistrict, Status = "ACTIVE"),"Title","Division"));

Collect(ColStateDropdown,MaximoState);

Collect(ColCountyDropdown,MaximoCounty);


ClearCollect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "A" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "B" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "C" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "D" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "E" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "F" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "G" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "H" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "I" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "J" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "K" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "L" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "M" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "N" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "O" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "P" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "Q" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "R" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "S" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "T" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "U" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "V" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "W" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "X" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "Y" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "Z" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "Z" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "0" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "1" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "2" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "3" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "4" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "5" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "6" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "7" )));

Collect(ColFacilityDropdown,Filter(Filter(MaximoFacility, Status = "ACTIVE"), StartsWith( Title, "8" )));


If( Connection.Connected,

    ClearCollect(

        MyItems,'Spill Reporting'

    );

    Set( statusText, "Online data" ),

    LoadData(MyItems,"MyItems",true);

    Set( statusText, "Local data" );

);

SaveData( MyItems, "MyItems" );

LoadData( MyItemsToPost, "MyItemsToPost", true );

--------------------------------------------------------------------------

Timer - On Timer End property

If( Connection.Connected,
    ForAll(
        MyItemsToPost,
        If(
            ThisRecord.FormModeValueIs = "New",
            Patch(
                'Spill Reporting',
                Defaults('Spill Reporting'),
                {
                    Division: ThisRecord.Division,
                    District: ThisRecord.District,
                    Facility: ThisRecord.Facility,
                    State: ThisRecord.State,
                    County: ThisRecord.County,
                    'Date/Time of Discovery': ThisRecord.'Date/Time of Discovery',
                    'Date/Time Reported to HSE': ThisRecord.'Date/Time Reported to HSE',
                    Pipeline: ThisRecord.Pipeline,
                    'Quantity of Release': ThisRecord.'Quantity of Release',
                    'Short Description of Release ': ThisRecord.'Short Description of Release ',
                    'Latitude/Longitude': ThisRecord.'Latitude/Longitude',
                    'NRC Reportable': ThisRecord.'NRC Reportable',
                    'NRC Reportable justification statement': ThisRecord.'NRC Reportable justification statement',
                    'T-State Reportable': ThisRecord.'T-State Reportable',
                    'T-State Justification': ThisRecord.'T-State Justification',
                    'PHMSA 30-Day Reportable': ThisRecord.'PHMSA 30-Day Reportable',
                    'PHMSA 30-Day reportable justification statement)': ThisRecord.'PHMSA 30-Day reportable justification statement)',
                    'State Reportable': ThisRecord.'State Reportable',
                    'State Reportable justification statement': ThisRecord.'State Reportable justification statement'
                }
            );
            Notify("Offline item Saved Successfully",Success,2000);
        );
        If(
            ThisRecord.FormModeValueIs = "Edit",
            Patch(
                'Spill Reporting',
                LookUp(
                    'Spill Reporting',
                    ID = Gallery1.Selected.ID
                ),
                {
                    Division: ThisRecord.Division,
                    District: ThisRecord.District,
                    Facility: ThisRecord.Facility,
                    State: ThisRecord.State,
                    County: ThisRecord.County,
                    'Date/Time of Discovery': ThisRecord.'Date/Time of Discovery',
                    'Date/Time Reported to HSE': ThisRecord.'Date/Time Reported to HSE',
                    Pipeline: ThisRecord.Pipeline,
                    'Quantity of Release': ThisRecord.'Quantity of Release',
                    'Short Description of Release ': ThisRecord.'Short Description of Release ',
                    'Latitude/Longitude': ThisRecord.'Latitude/Longitude',
                    'NRC Reportable': ThisRecord.'NRC Reportable',
                    'NRC Reportable justification statement': ThisRecord.'NRC Reportable justification statement',
                    'T-State Reportable': ThisRecord.'T-State Reportable',
                    'T-State Justification': ThisRecord.'T-State Justification',
                    'PHMSA 30-Day Reportable': ThisRecord.'PHMSA 30-Day Reportable',
                    'PHMSA 30-Day reportable justification statement)': ThisRecord.'PHMSA 30-Day reportable justification statement)',
                    'State Reportable': ThisRecord.'State Reportable',
                    'State Reportable justification statement': ThisRecord.'State Reportable justification statement'
                }
            );
            Notify(
                "Updated the Item ID " & Gallery1.Selected.ID & " Successfully",
                Success,
                3000
            );
        );
    );
    Clear(MyItemsToPost );
    SaveData(MyItemsToPost,"MyItemsToPost");
    ClearCollect(
        MyItems,'Spill Reporting'
    );
    SaveData( MyItems, "MyItems" );
    Set(
        ResetNewForm,
        true
    );
)
----------------------------------------------------------------------------

Comments