amralomari

powerapps stability

Oct 27th, 2025
2,134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Validate inputs
  2. If(
  3.     IsBlank(cmbCondition.Selected),
  4.     Notify("Please select a Condition", NotificationType.Error),
  5.     IsEmpty(cmbRack.SelectedItems),
  6.     Notify("Please select at least one Rack", NotificationType.Error),
  7.     IsBlank(txtDaysShift.Value) || Value(txtDaysShift.Value) <= 0,
  8.     Notify("Please enter a valid number of days", NotificationType.Error),
  9.    
  10.     // If validation passes, collect affected records BEFORE update
  11.     ClearCollect(
  12.         colAffectedRecords,
  13.         AddColumns(
  14.             Filter(
  15.                 SEL,
  16.                 cmbCondition.Selected.Value in Condition.Value &&
  17.                 !IsBlank(LookUp(cmbRack.SelectedItems, Value = Rack))
  18.             ),
  19.             OldEWD_Backup, EWD,
  20.             NewEWD_Calc, DateAdd(EWD, Value(txtDaysShift.Value), TimeUnit.Days),
  21.             ConditionText, cmbCondition.Selected.Value
  22.         )
  23.     );
  24.    
  25.     // Update records
  26.     ForAll(
  27.         colAffectedRecords,
  28.         Patch(
  29.             SEL,
  30.             LookUp(SEL, ID = ID),
  31.             {EWD: NewEWD_Calc}
  32.         )
  33.     );
  34.    
  35.     // Send email notification
  36.     Office365Outlook.SendEmailV2(
  37.         User().Email,
  38.         "EWD Update Notification - " & CountRows(colAffectedRecords) & " Records Modified",
  39.         "<!DOCTYPE html>
  40. <html>
  41. <head>
  42.    <style>
  43.        body { font-family: Arial, sans-serif; }
  44.        table { border-collapse: collapse; width: 100%; margin-top: 20px; }
  45.        th { background-color: #0078D4; color: white; padding: 10px; text-align: left; }
  46.        td { border: 1px solid #ddd; padding: 8px; }
  47.        tr:nth-child(even) { background-color: #f2f2f2; }
  48.        .summary { background-color: #E8F4FD; padding: 15px; border-radius: 5px; margin-bottom: 20px; }
  49.        .summary p { margin: 5px 0; }
  50.    </style>
  51. </head>
  52. <body>
  53.    <h2>EWD Update Notification</h2>
  54.    
  55.    <div class='summary'>
  56.        <p><strong>Updated By:</strong> " & User().FullName & " (" & User().Email & ")</p>
  57.        <p><strong>Date & Time:</strong> " & Text(Now(), "dd/mmm/yyyy hh:mm AM/PM") & "</p>
  58.        <p><strong>Records Affected:</strong> " & CountRows(colAffectedRecords) & "</p>
  59.        <p><strong>Days Shifted:</strong> " & txtDaysShift.Value & " day(s)</p>
  60.    </div>
  61.    
  62.    <h3>Updated Records:</h3>
  63.    <table>
  64.        <tr>
  65.            <th>ID</th>
  66.            <th>Title</th>
  67.            <th>Incubation Date</th>
  68.            <th>Mfg Date</th>
  69.            <th>Exp Date</th>
  70.            <th>Condition</th>
  71.            <th>EWD (Before)</th>
  72.            <th>EWD (After)</th>
  73.        </tr>
  74.        " &
  75.         Concat(
  76.             colAffectedRecords,
  77.             "<tr>
  78.                <td>" & Text(ID) & "</td>
  79.                <td>" & Title & "</td>
  80.                <td>" & Text(IncDate, "dd/mmm/yyyy") & "</td>
  81.                <td>" & Text(MfgDate, "dd/mmm/yyyy") & "</td>
  82.                <td>" & Text(ExpDate, "dd/mmm/yyyy") & "</td>
  83.                <td>" & ConditionText & "</td>
  84.                <td>" & Text(OldEWD_Backup, "dd/mmm/yyyy") & "</td>
  85.                <td>" & Text(NewEWD_Calc, "dd/mmm/yyyy") & "</td>
  86.            </tr>"
  87.         ) &
  88.         "
  89.    </table>
  90.    
  91.    <p style='margin-top: 20px; color: #666; font-size: 12px;'>This is an automated notification from the Stability Studies Management System.</p>
  92. </body>
  93. </html>",
  94.         {
  95.             Cc: "[email protected]; [email protected]",
  96.             Importance: "Normal"
  97.         }
  98.     );
  99.    
  100.     Notify(
  101.         "Successfully updated " & CountRows(colAffectedRecords) & " records and sent notification email!",
  102.         NotificationType.Success
  103.     );
  104.    
  105.     // Reset the form
  106.     Reset(cmbCondition);
  107.     Reset(cmbRack);
  108.     Reset(txtDaysShift)
  109. )
Advertisement
Add Comment
Please, Sign In to add comment