web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Service | Customer Service, Contact Center, Fie...
Suggested Answer

Subtracting Value on current record based on previous record

(0) ShareShare
ReportReport
Posted on by 50

Hello Dynamics 365 Community, 

I have a requirement where I need to subtract a value based on previous records value. 

For example :  

  • Entry number 001 :   has a employee field and has number 5 ( read only field)
  • Entry number 002 ( new record) :  has a add employee field and I enter 1 there, now employee field should have 4 
  • Entry number 003 ( new record) : should have 4 in Employee field (read only field), now I enter 2
  • Entry number 004 ( new record) : should have 2 in Employee field ( read only field)

Thanks. 

I have the same question (0)
  • Pankaj Gogoi Profile Picture
    3,177 on at

    Hi Manny,

    Here what I suggest.

    Create an auto number field and while creating the record fetch the row with the previous auto number. For instance, previous auto number is 1001 and current record auto number is 1002, then you can fetch the  record decrementing 1 from the current auto number.

    You can also create a Pre Operation plugin, then fetch the top 1 record based on the modified on desc and fetch the Employee field and set the current record employee field.

    Hope this helps

    PG

  • HughHu Profile Picture
    on at

    you can create a field with type whole number, then use a workflow for subtracting.

  • Manny Floyd Profile Picture
    50 on at

    Hi PG, thanks for getting back to me.

    I am using model driven app, and I do not have data type auto-number. Also, I am new to programming.

    I am now learning learning Pre-Op and Post-Op Plug Ins. Would it be possible for you to provide sample code?

    Appreciated,

    Manny Floyd

  • Suggested answer
    P. R. M Profile Picture
    739 on at

    Hi Manny,

    Lets try below solution:

    1. Create Plugin on Record creation/Update [Based on requirement. If Add Employee allows to enter only on create then register on Create else register on both]

    2. Inside Plugin, Get Previous Record. Query records order by CreatedOn/ModifiedOn Desc and get top 1 record with EmployeeField value (CurrentEmployees) - Can include if any other conditions also.

    3. Read current record value "Add Employee" from Target

    4. Calculate "CurrentEmployees - CurrentRecordAddEmployee" and set this to "EmployeeField" of current Record.

    Refer below link for Sample Plugin Code:

    community.dynamics.com/.../pre-image-and-post-image-in-dynamics-crm

  • Pankaj Gogoi Profile Picture
    3,177 on at

    Hi Manny,

    Microsoft documents sites are best for learning. Here is a tutorial for Plugin development

    docs.microsoft.com/.../tutorial-write-plug-in

    Learning for CE Development

    docs.microsoft.com/.../tutorials-resources-sdk

    You can also checkout the pluralsight courses. They have a 10 day free trial.

    www.pluralsight.com/.../dynamics-crm-developer-part1

    Hope this links helps you in getting started.

    Best Regards

    PG

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Service | Customer Service, Contact Center, Field Service, Guides

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 75 Super User 2025 Season 2

#2
Siv Sagar Profile Picture

Siv Sagar 52 Super User 2025 Season 2

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 42 Most Valuable Professional

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans