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 / Prevent duplicate Invo...
Power Apps
Unanswered

Prevent duplicate InvoiceNo for each firmname dropdown selection

(0) ShareShare
ReportReport
Posted on by 212

I have a SharePoint list that I have customized using PowerApps. I need to add a validation control to prevent duplicate InvoiceNo records being saved. I need to check for the FirmName which is a dropdown choice. I may have a unique FirmName with the same Invoice no and that is okay. I need a validation that checks the FirmName and InvoiceNo to check for unique InvoiceNo value.

 

Categories:
I have the same question (0)
  • JohnM86 Profile Picture
    590 on at

    Really you want invoice numbers to be unique and shouldn't really have two invoices of the same number I have created an invoicing system similar to what you are requesting that uses dropdowns link to client accounts, separate invoicing accounts, contacts and properties etc, the system also works out CIS rates (UK), Tax, ledger accounts, quantities, discounts etc.

     

    It will take a bit of work to get it up and running properly but the code I have is like:

     

    JohnM86_0-1681839580261.png

     

    JohnM86_1-1681839602598.png

    JohnM86_2-1681839614063.png

     

    the code on add row is

     

    /////////////////////Collect Invoices Line Items/////////////////////
    Collect(
    InvoiceRowsCollection,
    {
    ColDescription: TextInput1_3.Text,
    ColLedger: Dropdown1_2.SelectedText,
    ColUnits: TextInput2_6.Text,
    ColTotalAmount: TextInput3_3.Text,
    ColDiscount: TextInput3_4.Text
    }
    );

    /////////////////////Set Amount Variables and Strip Formatting/////////////////////

    Set(RawVar, Substitute( TextInput3_3.Text, "£", "" ));
    Set(RawVar2, Substitute( RawVar, ",", "" ));

    /////////////////////Set Discount Variables and strip formatting/////////////////////

    Set(RawDiscountVar, Substitute( TextInput3_4.Text, "£", "" ));
    Set(RawDiscountVar2, Substitute( RawDiscountVar, ",", "" ));

    /////////////////////Set Total Value of Line Items/////////////////////

    Set(VarTotalValue, VarTotalValue + Value(RawVar2));

    /////////////////////Set Sales Tax for Line Items/////////////////////

    Set(VarGST, VarGST + Value(RawVar2)*.2);

    /////////////////////Set Discount Amount for Line Items/////////////////////

    Set(varDiscount, varDiscount + Value(RawDiscountVar2));

    /////////////////////Set Discount Sales Tax for Line Items /////////////////////

    Set(VarDiscountGST, VarDiscountGST + Value(RawDiscountVar2)*.2);

    /////////////////////Set Discount Sales Tax for Line Items /////////////////////

    Set(varSubTotal, DataCardValue12_2.Text);

    /////////////////////Set Sales Tax Amount for CIs Labour /////////////////////

    If(Dropdown1_2.Selected.Ledger = "CIS Labour", Set(VarCISLRGST, VarCISLRGST + Value(RawVar2)*.2));

    /////////////////////Set Sales Tax Amount for CIS Mterials/////////////////////

    If(Dropdown1_2.Selected.Ledger = "CIS Materials", Set(VarCISMLRGST, VarCISMLRGST + Value(RawVar2)*.2));

    /////////////////////Reset Inputs/////////////////////
    Reset(TextInput1_3);
    Reset(TextInput2_6);
    Reset(TextInput3_3);
    Reset(TextInput3_4);
    Reset(Dropdown1_2);

    /////////////////////Set Formatted Numbers for Amount / Discounts////////////
    Set(FormattedNum, "");
    Set(FormattedDiscountNum, "");

     

     

    the code on generate 

     

    Patch(
    Invoices,
    Defaults(Invoices),
    {
    Client: LookUp(
    Accounts,
    '🏢 Account Name' = DataCardValue2_1.Selected.'🏢 Account Name'
    ),
    'Invoicing Account ': LookUp(
    Contacts,
    '📧 Email' = DataCardValue9_1.Selected.'📧 Email'
    ),
    Property: LookUp(
    properties,
    'Full Address' = DataCardValue10_2.Selected.'Full Address'
    ),
    Contact: LookUp(
    Contacts,
    '👤 Full Name' = DataCardValue8_2.Selected.'👤 Full Name'
    ),
    WO: LookUp(
    Projects_2,
    '🛠️ Project Name' = Dropdown2.Selected.'🛠️ Project Name'
    ),
    'Due Date': DateValue1_2.SelectedDate,
    'Date Sent': DatePicker1_2.SelectedDate,
    'Invoice Number': DataCardValue1_2.Text,
    'Is CIS?': DataCardValue15_2.Selected.Value,
    'CIS Deduction': Value(DataCardValue13_4.Text),
    Shipping: Value(TextInput4_2.Text),
    SubTotal: Value(DataCardValue12_2.Text),
    'Discount Amount': Value(DataCardValue3_3.Text),
    'Amount Due': Value(DataCardValue3_2.Text),
    Tax: Value(DataCardValue12_3.Text),
    'Additional Information': TextInput1.Text,
    'Invoice Date': DatePicker1_2.SelectedDate
    }
    );
    ForAll(
    InvoiceRowsCollection,
    Patch(
    'Invoice Tasks',
    Defaults('Invoice Tasks'),
    {
    Name: "Invoice Line Item" & DataCardValue1_2.Text,
    Description: ColDescription,
    Units: Value(ColUnits),
    'Total Amount': ColTotalAmount,
    'Invoice Number': DataCardValue1_2.Text,
    'Invoice Header': Label4_1.Text,
    'Ledger Account': TextInput2_5.Text,
    'CIS Deduction': Value(DataCardValue13_4.Text)

    }
    )
    );
    Notify(
    "Your invoice was successfully submitted",
    NotificationType.Success,
    5000
    );
    Clear(InvoiceRowsCollection);
    Set(
    VarTotalValue,
    0
    );
    Set(
    VarGST,
    0
    );
    Set(
    VarShippingGST,
    0
    );
    Set(
    VarCISLRGST,
    0
    );
    Set(
    VarCISMLRGST,
    0
    );
    Set(
    RawShippingVar2,
    Blank()
    );
    ///////////////////////Collect Invoice Numbers ////////////////////////
    //////////////////////////////////////////////////////////////////////

    ClearCollect(collectedInvoices, Invoices);
    ClearCollect(collectedInvoiceNumbers, Distinct(collectedInvoices, 'Invoice Number'));

    ///////////////////////Set the invoicenum variable as next consecutive invoice number ////////////////////////
    //////////////////////////////////////////////////////////////////////

    Set(InvoiceNum, Text(Last(Sort(collectedInvoiceNumbers, Value)).Value + 1, "00000"));

    Reset(TextInput4_2);
    Reset(DataCardValue3_3);
    Reset(DataCardValue2_1);
    Reset(DataCardValue9_1);
    Reset(DataCardValue10_2);
    Reset(DataCardValue8_2);
    Reset(TextInput1);
    Navigate(Menu);

     

     

    app on start

     

    ///////////////////////Collect Invoice Numbers ////////////////////////
    //////////////////////////////////////////////////////////////////////

    ClearCollect(collectedInvoices, Invoices);
    ClearCollect(collectedInvoicesNumbers, Distinct(collectedInvoices, 'Invoice Number'));

    ///////////////////////Set the invoicenum variable as next consecutive invoice number ////////////////////////
    //////////////////////////////////////////////////////////////////////

    Set(InvoiceNum, Text(Last(Sort(collectedInvoiceNumbers, Value)).Value + 1, "00000"));

    ///////////////////////Create Collection Ledger Acccounts ////////////////////////
    //////////////////////////////////////////////////////////////////////


    ClearCollect(
    LedgerAccounts,
    {Number:1, Ledger: "Sales/Services"},
    {Number:2, Ledger: "Sales/Materials"}
    );
    ClearCollect(
    CISLedgerAccounts,
    {Number:3, Ledger: "CIS Labour"},
    {Number:4, Ledger: "CIS Materials"}
    );

    ///////////////////////Reset Variables ////////////////////////
    //////////////////////////////////////////////////////////////////////
    //////////////////////Invoices
    Set(varDiscount, 0);
    Set(VarDiscountGST,0);
    Set(VarTotalValue, 0);
    Set(VarShippingValue, 0);
    Set(VarGST, 0);
    Set(VarShippingGST, 0);
    Set(varSubTotal, Blank());
    /////////////////////////////////////////Quotes
    Set(varQuotesDiscount, 0);
    Set(VarQuotesDiscountGST,0);
    Set(VarQuotesTotalValue, 0);
    Set(VarQuotesShippingValue, 0);
    Set(VarQuotesGST, 0);
    Set(VarQuotesShippingGST, 0);
    Set(varQuotesSubTotal, Blank());
    /////////////////////////////////////////CIS
    Set(VarCISLRGST, 0);
    Set(VarCISMLRGST, 0);

     

     

    I hope this helps get the ball rolling 

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
Haque Profile Picture

Haque 103

#2
WarrenBelz Profile Picture

WarrenBelz 82 Most Valuable Professional

#3
wolenberg_ Profile Picture

wolenberg_ 67 Super User 2026 Season 1

Last 30 days Overall leaderboard