Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

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

(0) ShareShare
ReportReport
Posted on by 212

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
    27,823 Moderator 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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,923 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,788 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans