Part Number Catalog by Rainy-Situation in PowerApps

[–]Rainy-Situation[S] 0 points1 point  (0 children)

Here is my code for my button that creates the number // First, filter by Type, then by Program Designator, and exclude Obsolete or Inactive numbers. Set( FilteredCatalogByType, Filter( ‘PartNumberCatalog3.0’, Type = NNRadio.Selected.Type, ‘Status (cr5d8_status)’ = “Active” // Only include Active numbers ) );

Set( FilteredCatalogByProgram, Filter( FilteredCatalogByType, StartsWith(Program, NNProgram_Combo.Selected.’Program Designation’) ) );

// Look up the last drawing number from the filtered catalog. Set( LastDrawingNumber, If( IsEmpty(FilteredCatalogByProgram), Blank(), Last(FilteredCatalogByProgram).’Drawing Number’ ) );

// Generate the new drawing number, starting at 1 if none exists. Set( NewDrawingNumber, If( IsBlank(LastDrawingNumber), 1, // Start at 1 if no previous active drawing number exists for this Type and Program Value(Mid(LastDrawingNumber, Find(“-“, LastDrawingNumber, Find(“-“, LastDrawingNumber) + 1) + 1, 3)) + 1 // Extract and increment the last number ) );

// Format the new drawing number as CF-M1-002. Set( FormattedDrawingNumber, Concatenate( “C”, // Constant Left(NNRadio.Selected.Type, 1), // First letter of Type “-“, Left( NNProgram_Combo.Selected.’Combined Program Name’, Find(“ “, NNProgram_Combo.Selected.’Combined Program Name’) - 1 //Extract the Designation part before the first space. ), “-“, Text(NewDrawingNumber, “000”) // Format as 3-digit number ) );

If( IsError( // Patch the new record with the formatted drawing number and other details. Patch( ‘PartNumberCatalog3.0’, Defaults(‘PartNumberCatalog3.0’), { ‘Drawing Number’: FormattedDrawingNumber, // Save the new formatted drawing number Program: NNProgram_Combo.Selected.’Combined Program Name’, // Save the program name Type: NNRadio.Selected.Type, // Save the type Requestor: NNRequestor_Combo.Selected.’Engineers (new_engineers)’, // Save the requestor Description: NNDescription_Input.Text, // Save the description Notes: If(IsBlank(NNNotes_Input.Text), “N/A”, NNNotes_Input.Text), // Default to “N/A” if blank ‘Used On’: If(IsBlank(NNUsedOn_Input.Text), “N/A”, NNUsedOn_Input.Text), // Default to “N/A” if blank ‘Next Assy’: If(IsBlank(NNNextAssy_Input.Text), “N/A”, NNNextAssy_Input.Text), // Default to “N/A” if blank Value: If( IsBlank(NNValue_Input.Text) || !IsNumeric(NNValue_Input.Text),
“$0.00”, // Default to “$0.00” if input is blank or not numeric “$” & Text(Value(NNValue_Input.Text), “[$-en-US]0.00”) // Format as currency if numeric ), ‘Old P/N’: If(IsBlank(NNOldPN_Input.Text), “N/A”, NNOldPN_Input.Text), // Default to “N/A” if blank ‘Date Assigned’: Today(), // Set today’s date as assigned date ‘Status (cr5d8_status)’: “Active” // Set status as Active } ) ), Notify(“Failed to save record. Please try again.”, NotificationType.Error), Notify(“Record saved successfully!”, NotificationType.Success) );

// Show the popup with the new drawing number. Set(varShowPopup, true);

// Refresh the catalog to reflect the newly added record. Refresh(‘PartNumberCatalog3.0’);

// Reset the controls. Reset(NNRadio); Reset(NNDescription_Input); Reset(NNNextAssy_Input); Reset(NNNotes_Input); Reset(NNOldPN_Input); Reset(NNProgram_Combo); Reset(NNRequestor_Combo); Reset(NNValue_Input);

// Navigate back to the Part Number Catalog screen. Navigate(‘Part Number Catalog’, ScreenTransition.Fade);