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 :
Microsoft Dynamics AX (Archived)

Product Variants Odata Update Error

(0) ShareShare
ReportReport
Posted on by 30

I'm using Odata to update a variant in the Product Variants entity in D365. I have created proxy classes for this using the Odata Client Code Generator. I am first querying a specific product variant that returns a valid variant and then updating a 2 fields. I do not update the ProductVariantNumber field. When calling the SaveChanges method I get an error from D365:

"Update not allowed for field 'ProductVariantNumber'"

It seems the Odata call is trying to update the Product Variant Number even though I didn't change it and it appears D365 does not allow you to edit this value.

Here's my code:

var productVariant = context.ProductVariants
.AddQueryOption("$filter",
$"ProductMasterNumber eq '{productNumberEscaped}' and ProductConfigurationId eq '{configIdEscaped}'")
.FirstOrDefault();



if (productVariant != null)
{
productVariant.ProductDescription = dr["ProductDescription"].ToString();
productVariant.ProductName = dr["ProductName"].ToString();

context.UpdateObject(productVariant);



context.SaveChanges();
}


*This post is locked for comments

I have the same question (0)
  • Verified answer
    jbolkovatz Profile Picture
    30 on at

    I was able to resolve this by removing the ProductVariantNumber from the properties submitted in the Odata call within the context.Configurations.RequestPipeline.OnEntryStarting event.

    Here's the code:

    Extension Methods:
    
    public static void RemoveProperties(this ODataResource entry, params string[] propertyNames)
            {
    
                var properties = entry.Properties as List<ODataProperty>;
                if (properties == null)
                {
                    properties = new List<ODataProperty>(entry.Properties);
                }
    
                var propertiesToRemove = properties.Where(p => propertyNames.Any(rp => rp == p.Name));
                foreach (var propertyToRemove in propertiesToRemove.ToArray())
                {
                    properties.Remove(propertyToRemove);
                }
    
                entry.Properties = properties;
    
            }
    
            public static void AddProperties(this ODataResource entry, params ODataProperty[] newProperties)
            {
                var properties = entry.Properties as List<ODataProperty>;
                if (properties == null)
                {
                    properties = new List<ODataProperty>(entry.Properties);
                }
    
                properties.AddRange(newProperties);
    
                entry.Properties = properties;
    
            }
    
    
    Event:
    
    context.Configurations.RequestPipeline.OnEntryStarting(arg =>
              {
                  arg.Entry.RemoveProperties("ProductVariantNumber");
              });


  • Douglas Noel Profile Picture
    3,905 on at

    Hi,

    many thanks for posting this information about the solution you found.

    This could be very helpful in similar cases.

    Douglas

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans