Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Unanswered

Validation on Form level for multiple expenses on total sum of amount

Posted on by 216

Hi team,

Please help me in this solution.

I have a expense category as OPD expenses and i wanted to put validation on form if expense amount is more than 5000 INR. I can add multiple expenses in 1 expense report so I have used on validating method but it not calculating the sum. Please help

pastedimage1639077209845v1.png

[FormControlEventHandler(formControlStr(TrvExpenses, TrvExpTrans_AmountMST), FormControlEventType::Validating)]
public static void TrvExpTrans_AmountMST_OnValidating(FormControl sender, FormControlEventArgs e)
{
FormRun formRun = sender.formRun();

FormDataSource formDataSource = formRun.dataSource(formDataSourceStr(TrvExpenses,TrvExpTrans ));

TrvExpTrans TrvExpTrans = formDataSource.cursor();

real totalamt;

if(fieldNum(TrvExpTrans, AmountCurr))
{
select sum(AmountCurr) from trvExpTrans where
trvExpTrans.CostType == 'OPD Expenses'
&& trvexptrans.CreatedBy == curUserId() ;

totalamt = trvexptrans.AmountCurr;

if( totalamt >5000 && trvExpTrans.CostType == 'OPD Expenses' && trvexptrans.CreatedBy == curUserId())
{
throw Error ("OPD Expense cannot be claimed more than 5000 in a year");
}
}
}

  • GirishS Profile Picture
    GirishS 27,832 Super User 2024 Season 1 on at
    RE: Validation on Form level for multiple expenses on total sum of amount

    Hi,

    Have you debugged the code and find out whether if condition(checking the field num) returns true.

    I don't think this one doesn't work for your scenario.

    Try to use the COC command on table level validate method.

    Thanks,

    Girish S.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans