// Initialize a variable to store the generated Request ID
Set(
RequestID,
Blank()
);
// Create the initial record to capture the Request ID
Set(
RequestID,
Patch(
'Equipment Requests',
Defaults('Equipment Requests'),
{
'Equipment Qty': 1,
'Equipment Category': LookUp(
'Equipment Categories',
EquipCategories = First(CartItems).EquipmentCategory
),
// Reference the first item in CartItems
'Notes/Comments': First(CartItems).EquipmentNotes,
Job: ctx_seljobitem,
// Reference the form control directly
'Cost Code': txt_ER_CCValue.Text,
// Reference the form control directly
'Date & Time Needed': DateValue(
Text(
dp_ER_DateValue.SelectedDate,
"[$-en-US]yyyy-mm-dd"
)
) + TimeValue(Text(dd_ER_HourValue.Selected.Value & ":" & dd_ER_MinValue.Selected.Value)),
// Combine date and time
'Anticipated End Date': dp_ER_EndDateValue.SelectedDate,
// Reference the form control directly
'Delivery Contact Name': txt_ER_ConNaValue.Text,
// Reference the form control directly
'Delivery Contact Phone #': txt_ER_ConNuValue.Text// Reference the form control directly
}
).'Request ID #'
);
// Iterate over each item in the cart
ForAll(
CartItems,
// Check if the qty is greater than 1
If(
Value(EquipmentQty) > 1,
// Create multiple rows for items with qty > 1
ForAll(
Sequence(Value(EquipmentQty)),
Patch(
'Equipment Requests',
Defaults('Equipment Requests'),
{
'Request ID #': RequestID,
'Equipment Qty': 1,
'Equipment Category': LookUp(
'Equipment Categories',
EquipCategories = EquipmentCategory
),
'Notes/Comments': EquipmentNotes,
Job: ctx_seljobitem,
'Cost Code': txt_ER_CCValue.Text,
'Date & Time Needed': DateValue(
Text(
dp_ER_DateValue.SelectedDate,
"[$-en-US]yyyy-mm-dd"
)
) + TimeValue(Text(dd_ER_HourValue.Selected.Value & ":" & dd_ER_MinValue.Selected.Value)),
'Anticipated End Date': dp_ER_EndDateValue.SelectedDate,
'Delivery Contact Name': txt_ER_ConNaValue.Text,
'Delivery Contact Phone #': txt_ER_ConNuValue.Text
}
)
),
// Create a single row for items with quantity 1
Patch(
'Equipment Requests',
Defaults('Equipment Requests'),
{
'Request ID #': RequestID,
'Equipment Qty': 1,
'Equipment Category': LookUp(
'Equipment Categories',
EquipCategories = EquipmentCategory
),
'Notes/Comments': EquipmentNotes,
Job: ctx_seljobitem,
'Cost Code': txt_ER_CCValue.Text,
'Date & Time Needed': DateValue(
Text(
dp_ER_DateValue.SelectedDate,
"[$-en-US]yyyy-mm-dd"
)
) + TimeValue(Text(dd_ER_HourValue.Selected.Value & ":" & dd_ER_MinValue.Selected.Value)),
'Anticipated End Date': dp_ER_EndDateValue.SelectedDate,
'Delivery Contact Name': txt_ER_ConNaValue.Text,
'Delivery Contact Phone #': txt_ER_ConNuValue.Text
}
)
)
);
// Clear the cart and forms after submission
Clear(CartItems);
UpdateContext({ctx_seljobitem: Blank()});
Reset(txt_ER_CCValue);
Reset(dp_ER_DateValue);
Reset(dd_ER_HourValue);
Reset(dd_ER_MinValue);
Reset(dp_ER_EndDateValue);
Reset(txt_ER_ConNaValue);
Reset(txt_ER_ConNuValue);
Reset(txt_ER_QTYValue);
Reset(cb_ER_EquCatValue);
Reset(txt_ER_NotesValue);
// Notify the user of successful submission
Notify(
"Request submitted successfully",
NotificationType.Success
);
Navigate(
'Equipment Request Form',
ScreenTransition.None
);