PowerApps SubmitForm到另一个数据源

时间:2018-06-27 18:28:16

标签: powerapps

我正在尝试实现Outlook之类的离线功能。如果处于脱机状态,则应将值从EditForm1放置到本地集合(发件箱)中。是否可以根据Connection.Connected变量将editform提交到不同的源?然后,我将创建一个计时器,该计时器每隔x秒提交一次提交。

1 个答案:

答案 0 :(得分:0)

如果我的理解正确,您想将EditForm1中当前的内容保存到本地集合中,并且在再次接收到互联网连接后,您想要再次提交表单。

如果您已连接到Internet,则希望使用某种条件来保存当前表单中的数据,否则将其收集到一个临时集合中。

If(ToggleIsConnected.Value,
    //If you are connected to the internet, then write the data to the database.
    SubmitForm(Form1),

    //If you are NOT connected to the internet, then write the data to a temporary collection to be written later.
    Collect(temporary,
        {id: Max(temporary,id)+1,
            column1: InputColumn1.Text,
            column2: InputColumn2.Text
        }
    );
    SaveData(temporary,"temporary")
)

您可以使用Toggle来检查互联网连接。如果您失去连接,在本地保存数据并重新获得连接,则切换开关将触发并自动执行OnCheck操作:

If(!IsEmpty(temporary),
    // If the connection returns and there are records to be written, 
    // then perform these actions:
    ForAll(temporary,
        // For each of the records in the temporary collection, 
        // save their data to a new row in the connected datasource.

        // If writing was successful, copy it to a collection called 'success' 
        // to identify it.
        Collect(success,
            {id: id,
                Record:                     
                    Patch(datasource,Defaults(datasource),
                        {column1: column1,
                            column2: column2
                        }
                    )
            }
        )
    );

    If(IsEmpty(Errors(datasource)),
        // If there are no errors with the datasource, 
        // go ahead and clear the entire temporary collection since you're writing.
        Clear(temporary),

        // Otherwise if there is an error, remove only the records that were successful. 
        // Then clear the successful records.
        // Keep records that had an error so they could be attempted later.
        Remove(temporary,Filter(temporary,id exactin Filter(success,!IsBlank(Record)).id));
        Clear(success)
    )
)

请注意,在这里,我使用Patch()保存临时集合中的内容。除非填写表单,否则我将无法使用SubmitForm。

还需要执行更多步骤来进一步实现这一目标。有关更多详细信息,请参阅我关于此主题的视频: https://www.youtube.com/watch?v=j30xOM5OmRE