Hi @Daniel20
Firstly use variables to store the values of some expressions that are repeated multiple times, such as CBTipoEvento.Selected.Value, CBProyectoFR.Selected.Listadeproyectos, and CBReporta.Selected.Value.
Secondly collections to store the data that you want to patch to the database, instead of using a long list of fields and values. Collections are faster and more flexible than patching individual fields. Lastly the With to create a temporary scope for variables and functions, instead of using multiple UpdateContext functions. With lets you define one or more variables or functions and use them within a block of code.
An example of your code:
With(
{
// Define some variables to store the repeated expressions
tipoEvento: CBTipoEvento.Selected.Value;
proyecto: CBProyectoFR.Selected.Listadeproyectos;
reporta: CBReporta.Selected.Value;
pdf: PDF(Container6_1);
// Define a collection to store the data for the FlashReport database
dataFlashReport: Collect(
{
LugarAccidente: TILugarFR.Text;
Proyecto: proyecto;
CelularActual: Value(TICelular.Text);
....
}
);
// Define a table of controls to reset
controlsToReset: Table(
TILugarFR;
CBProyectoFR;
TICelular;
...
)
};
// Use the variables and functions within this block of code
Concurrent(
// Send an email with the pdf attachment
Office365Outlook.SendEmailV2(
User().Email;
If(
tipoEvento = "Incidente";
"Flash Report: " & "Ha ocurrido un " & "INCIDENTE" & "en el proyecto de " & proyecto;
"Flash Report: " & "Ha ocurrido un " & tipoEvento & " " & "en el proyecto de " & proyecto & "generando un daño."
);
If(
tipoEvento = "Incidente";
"...";
tipoEvento = "No Conformidad";
"...";
"...."
);
{
Importance: "Alta";
Attachments: Table(
{
ContentBytes: pdf;
Name: "Flash Report " & ".pdf"
}
)
}
);
// Update the FlashReport database with the collection
Patch(
FlashReport;
Defaults(FlashReport);
dataFlashReport
)
);
// Reset the controls using ForAll
ForAll(
controlsToReset;
Reset(ThisRecord.Value)
)
)
If you have any questions or feedback, please let me know. Have a great day! 😊
-----------------------
PowerYsa Power Platform Enthusiast [LinkedIn] | [Youtube]
I love to share my knowledge and learn from others. If you find my posts helpful, please give them a thumbs up 👍 or mark them as a solution ✔️. You can also check out my [@PowerYSA] for some cool solutions and insights. Feel free to connect with me on any of the platforms above. Cheers! 🍻