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. 

  • Pankaj Gogoi Profile Picture
    Pankaj Gogoi 3,177 on at
    RE: Subtracting Value on current record based on previous record

    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

  • Suggested answer
    P. R. M Profile Picture
    P. R. M 739 on at
    RE: Subtracting Value on current record based on previous record

    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

  • Manny Floyd Profile Picture
    Manny Floyd 50 on at
    RE: Subtracting Value on current record based on previous record

    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

  • HughHu Profile Picture
    HughHu on at
    RE: Subtracting Value on current record based on previous record

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

  • Pankaj Gogoi Profile Picture
    Pankaj Gogoi 3,177 on at
    RE: Subtracting Value on current record based on previous record

    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

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

Announcing Our 2025 Season 1 Super Users!

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

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans