web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Reduce and optimize fu...
Power Apps
Answered

Reduce and optimize functions

(0) ShareShare
ReportReport
Posted on by 139

Good evening, any suggestions to be able to reduce the following functions and make them more optimal and faster?

UpdateContext({varSpinner: true});;
UpdateContext({varFlasReport: true});;
UpdateContext(
{
varPDF: PDF(Container6_1);
ExpandContainers: true
}
);;
Concurrent(
Office365Outlook.SendEmailV2(
User().Email;
If(
CBTipoEvento.Selected.Value = "Incidente";
"Flash Report: " & "Ha ocurrido un " & "INCIDENTE" & "en el proyecto de " & CBProyectoFR.Selected.Listadeproyectos;
"Flash Report: " & "Ha ocurrido un " & CBTipoEvento.Selected.Value & " " & "en el proyecto de " & CBProyectoFR.Selected.Listadeproyectos & "generando un daño."
);
If(
CBTipoEvento.Selected.Value = "Incidente";
"Se pudo haber producido un daño a uno o mas de nuestros trabajadores, tomemos atencion a los actos y condiciones subestandares que pudieran estar presentandose en nuestros proyectos para evitar la ocurrencia de un accidente.";
CBTipoEvento.Selected.Value = "No Conformidad";
"Se ha producido una No Conformidad que esta nos sirva para poder implementar controles adecuados y evitar una posible perdida mayor.";
"Se ha producido un daño a uno de nuestros trabajadores, pongamos atencion a los actos y condiciones en nuestra obra para evitar la recurrencia del daño. Recordemos que ninguna actividad es tan importante que se deba realizar sin seguridad. NINGUNA."
);
{
Importance: "Alta";
Attachments: Table(
{
ContentBytes: varPDF;
Name: "Flash Report " & ".pdf"
}
)
}
);
Patch(
FlashReport;
Defaults(FlashReport);
{
LugarAccidente: TILugarFR.Text;
Proyecto: CBProyectoFR.Selected.Listadeproyectos;
CelularActual: Value(TICelular.Text);
FechaHora: DPFechaFR.SelectedDate;
Hora: TIHora.Text;
TipoAccidente: CBTipoEvento.Selected.Value;
EmpresaInvolucrada: CBEmpresa.Selected.Title;
'Jefe Inmediato': CBJefe.Selected.Value;
ParteAfectada: CBParteAfectada.Selected.Value;
DañoProceso: TIDaño.Text;
TrabajadorAfectado: CBTrabajador.Selected.Apellidos;
PuestoTrabajo: TICargo.Text;
Edad: Value(TIEdad.Text);
Experiencia: TIExperiencia.Text;
RealPersonal: Value(CBCRP.Selected.Value);
RealPatrimonial: Value(CBCRPAT.Selected.Value);
PotencialPersonal: Value(CBCPPER.Selected.Value);
PotencialPatrimonial: Value(CBCPP.Selected.Value);
Descripcion: TIDescripcionFR.Text;
AccionesInmediatas: TIAcciones.Text;
ElaboradoPor: CBReporta.Selected.Value;
CargoElab: LblCargoReporta.Text;
Email: TIEmailReporta.Text;
Telefono: TICelReporta.Text;
Imagen01: UploadedImage1.Image;
Imagen02: UploadedImage1_1.Image;
Codigo: TICodigo.Text
}
)
);;
Concurrent(
Reset(TILugarFR);
Reset(CBProyectoFR);
Reset(TICelular);
Reset(DPFechaFR);
Reset(TIHora);
Reset(CBTipoEvento);
Reset(CBEmpresa);
Reset(CBJefe);
Reset(CBParteAfectada);
Reset(TIDaño);
Reset(CBTrabajador);
Reset(TICargo);
Reset(TIEdad);
Reset(TIExperiencia);
Reset(CBCRP);
Reset(CBCRPAT);
Reset(CBCPPER);
Reset(CBCPP);
Reset(TIDescripcionFR);
Reset(TIAcciones);
Reset(CBReporta);
Reset(TIEmailReporta);
Reset(TICelReporta);
Reset(AddMediaButton1);
Reset(AddMediaButton1_1);
Reset(TICodigo);
UpdateContext({varFlasReport: false})
);;
UpdateContext({varSpinner: false})

 

I appreciate your support to little by little continue growing in my knowledge of PowerApps.

Categories:
  • Verified answer
    SpongYe Profile Picture
    5,909 Super User 2026 Season 2 on at

    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! 🍻

  • CU-18081211-6 Profile Picture
    9,272 Moderator on at

    @Daniel20 ,

    There is not much you can do.

    The only thing I can propose to reduce the code is if you use standard controls (not modern one). is to eliminate the reset concurrent function part and replace it with setting a Boolean context variable (resetAll) first to false and right after set to true. In parallel set the Reset property for all controls you concurrently want to reset to the new variable.

    So, in your formula add:

    UpdateContext({resetAll:false});;UpdateContext({resetAll:true})

    Hope it helps !

     

  • Daniel20 Profile Picture
    139 on at

    Have a great day!  Thanks

  • Daniel20 Profile Picture
    139 on at

    @bobesponja One more question on the subject of collections, I am trying to use them in most cases but I have some lists of more than 2000 items and there I have the restriction that is why I try to use the long list with filters in this case. Any better option?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 409 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 252 Most Valuable Professional

Last 30 days Overall leaderboard