web
You’re offline. This is a read only version of the page.
close
Skip to main content
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);

}

I have the same question (0)
  • Suggested answer
    Parag Chapre Profile Picture
    12,254 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.

  • AnishKM Profile Picture
    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?

  • Parag Chapre Profile Picture
    12,254 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.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 1,964

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 564 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans