Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

Leave Request creation - Record Already Exists error

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.

  • net aspect Profile Picture
    net aspect 15 on at
    RE: Leave Request creation - Record Already Exists error

    Thanks Parag, it is working now (I can create leave requests via the API and the Dynamics interface).

    One issue with number sequences however:

    When I create a leave request via the API, the next number in the number sequence doesn't increment on the number sequences page.

    This means that when I create a leave request via the interface it results in "Record already exists error" because it is trying to use a number for a leave request that was created via the API.

    Hence it means I can only create via the API and not the interface (unless the next number is manually edited).  I would like it to work from both API and interface.

    When I am creating a leave request via the API I am supplying my own number sequence id (calculated by finding the last highest number sequence id).

    I tried submitting a leave request via the API without a RequestId, but this resulted in the message "Time off request in Completed state cannot be edited".  It seems to think it is editing an existing request.  I was hoping the system would just generate another number for the request since no number was supplied.

  • net aspect Profile Picture
    net aspect 15 on at
    RE: Leave Request creation - Record Already Exists error

    HI Andre

    Please ignore my earlier post (I'm going to delete it).

    I found some pre existing records with lower number sequences than the "next sequence".

    So I changed the next number sequence to be a higher number and it is all working now!  

    Thanks

    Bill

  • net aspect Profile Picture
    net aspect 15 on at
    RE: Leave Request creation - Record Already Exists error

    ,,,

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,280 Super User 2024 Season 2 on at
    RE: Leave Request creation - Record Already Exists error

    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?

  • Suggested answer
    Parag Chapre Profile Picture
    Parag Chapre 12,271 Most Valuable Professional on at
    RE: Leave Request creation - Record Already Exists error

    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.

  • net aspect Profile Picture
    net aspect 15 on at
    RE: Leave Request creation - Record Already Exists error

    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
    Parag Chapre 12,271 Most Valuable Professional on at
    RE: Leave Request creation - Record Already Exists error

    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.

  • Suggested answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,280 Super User 2024 Season 2 on at
    RE: Leave Request creation - Record Already Exists error

    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).

  • net aspect Profile Picture
    net aspect 15 on at
    RE: Leave Request creation - Record Already Exists error

    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.

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,280 Super User 2024 Season 2 on at
    RE: Leave Request creation - Record Already Exists error

    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.  

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans