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

Update PositionWorkerAssignments Entity via. OData Not Working

(0) ShareShare
ReportReport
Posted on by

Below code is written for updating "validTo" field for PositionWorkerAssignments entity in D365.

However no error is thrown, but data is not updated in the table/entity.

var query = Context.PositionWorkerAssignments.Where(s => s.PersonnelNumber == associate.PersonNumber) as DataServiceQuery<PositionWorkerAssignment>;
var response = await query.ExecuteAsync().ConfigureAwait(false);
var workerAssignment = response.FirstOrDefault();

if (workerAssignment != null)
{
var workerAssignmentCollection = new DataServiceCollection<PositionWorkerAssignment>(Context);
workerAssignmentCollection.Add(workerAssignment);


workerAssignment.ValidTo = DateTime.UtcNow.Date; //ending assignment


Context.UpdateObject(workerAssignment);
var saveResponse = await Context.SaveChangesAsync(SaveChangesOptions.PostOnlySetProperties).ConfigureAwait(false);

}

  • Parag Chapre Profile Picture
    Parag Chapre 12,248 Most Valuable Professional on at
    RE: Update PositionWorkerAssignments Entity via. OData Not Working

    As per my information, When you create a new record then it adjusts the previous record and creates a new record.

    When you edit the record then it just adjusts the current record.

    Please check the data entity methods and try to debug the code.

  • AnishKM Profile Picture
    AnishKM on at
    RE: Update PositionWorkerAssignments Entity via. OData Not Working

    But even if we need to add a new record? should we end(update) the initial assignment?

  • Suggested answer
    Parag Chapre Profile Picture
    Parag Chapre 12,248 Most Valuable Professional on at
    RE: Update PositionWorkerAssignments Entity via. OData Not Working

    Hi Anish,

    I am not sure how this handles in Odata but when updating Valid To value you need to consider whether you want to create a new record, correction. This table is Date effective.

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,307 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans