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 :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Leave Request creation - Record Already Exists error

(0) ShareShare
ReportReport
Posted on by 15

I am trying to create leave requests in Dynamics HR programmatically using C# submitting JSON requests via the API.

I am submitting a JSON request to the Dynamics URL/namespace and "data/LeaveRequests" address.  Sometimes it creates a leave request fine, so it definitely works ok on occasion.  Most times it just says "record already exists".  However a leave request on the leave date requested for the person definitely does not exist.  So what record exists exactly (the error doesn't say)?  Sometimes the submission works, but mostly it doesn't

{
"dataAreaId": "org",
"LeaveType": "Annual Leave",
"LeaveDate": "2021-02-11T00:00:00Z",
"PersonnelNumber": "10045",
"RequestDate": "2021-01-01T06:45:23Z",
"Comment": "Test comment",
"Status": "Completed",
"Amount": 1,
"HalfDayDefinition": "None"
}

Does anyone have any example of create leave request via the api? and also for multiple days?

I also tried adding leave requests via the Dynamics HR interface and this can also result in the record already exists message.

Any help greatly appreciated.

I have the same question (0)
  • Suggested answer
    Parag Chapre Profile Picture
    12,254 Most Valuable Professional on at

    HI billwinder2,

    Are you checking the condition whether the record exists? Also, check whether the new number sequence generated for each request.

  • net aspect Profile Picture
    15 on at

    HI Parag

    Thankyou for your advice.

    I am not checking whether a leave event exists on that date for the user, however I know there isn't one from viewing their record on the Dynamics HR interface.

    The new number sequence suggestion sounds like a potential lead.  Do you know how I generate a new number for each request through Json/API?  I would have hoped that a new number would be generated automatically per request like most systems would do, so seems odd to have to do this yourself.

    I can find very little information about programming with Dynamics HR api online, the only link I have found is below.

    docs.microsoft.com/.../hr-developer-entities

    Are there any other information sources on developing with Dynamics HR and leave requests etc?

    Thanks for taking the time to respond.

    Bill

  • André Arnaud de Calavon Profile Picture
    301,075 Super User 2025 Season 2 on at

    Hi Billwinder2,

    Can you check if you have enabled the 'Continuous' option on the number sequence for the Leave request IDs? If so, there might be a status list with incorrect unused numbers. It would be recommended to not have 'Continuous' enabled.  

  • net aspect Profile Picture
    15 on at

    Thanks alot for your feedback.  I am very much new to Dynamics HR (background in Dynamics CRM).

    I checked out the number sequence and Continuous is set to no.

    numberseq.jpg

    I find that I can create 1 leave request via the Dynamics HR interface, but after that I get this "Record already exists" error, or it appears that way.  So these id's and the number sequence feels like it could be the problem.

    I have also created some leave requests via the API by submitting JSON, but often again get the "Record already exists".  Typically in the JSON request I am not submitting a record id with it (I was thinking it might create one automatically).  But maybe I need to generate a request id I am not sure.

    But it seems strange that even via the interface there are issues with the leave requests.

  • Suggested answer
    André Arnaud de Calavon Profile Picture
    301,075 Super User 2025 Season 2 on at

    Hi Billwinder2,

    Did you check if the interface did create a Leave request ID automatically or if this is left empty? If it is getting the IDs then or it will try to create a duplicate or there might be another index on the table which does not allow duplicates.

    For the duplicates:

    You can check if there are Leave requests in your environment with a same or larger number then the Next mentioned on the pre-allocation or the Next value from the field group Number allocation.

    By writing this, you can also try to disable the Pre allocation to see if this solves your issue.

    If you continue having the issue after these suggestions, I would recommend to create a ticket for Microsoft Support as I can't verify the index part on Human Resources. (Have a trial only).

  • Suggested answer
    Parag Chapre Profile Picture
    12,254 Most Valuable Professional on at

    Hi Billwinder2,

    At this moment, I will suggest you do the below things.

    1. Try to create a Leave request manually in the system.

    2. Verify whether a new number sequence created in the system and a Leave request created successfully.

    If the above steps are completed then try to create a Leave request through API.

    I did the above steps in my system and It is generating a new number sequence and the Leave request is creating through API call.

    You can attach your code here in a text file. I will verify what is the issue if needed.

  • net aspect Profile Picture
    15 on at

    Thanks again for your help.  When I try to add a leave request manually in the system it almost always says "The record already exists" - I am doing this via the "Request time off" button..  It doesn't matter which user or what date I add it.  On a very rare occasion it lets me add it perhaps 1/10 or 1/20 times.

    Screen picture below:

    shot1.jpg

    Is there some sort of cleanup or intervention that can be done on the "number sequence"....?

    shot2.jpg

    5340.numberseq.jpg

    I prevoiusly created some leave requests via the API (I did manage to create some on occasion but mostly it failed), could the number sequence have become corrupted in some way?  

    These number sequences seem an oddly complicated way of doing something that should be very seamless and simple!

    Thanks again.

  • Suggested answer
    Parag Chapre Profile Picture
    12,254 Most Valuable Professional on at

    Hi Bill,

    The problem is with the Number sequence. Just try with a Manual number sequence and create a new record manually. If this is successful then try with API and provide RequestId value.

  • André Arnaud de Calavon Profile Picture
    301,075 Super User 2025 Season 2 on at

    Hi Billwinder2,

    I provided above some thoughts on checking if it works without pre-allocation and if there are already requests with a number higher than 3448 or 3450. Have you checked this already?

  • net aspect Profile Picture
    15 on at

    ,,,

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 551 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 450 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans