web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Trouble creating OpenTradeAgreementJournalHeaderV2 Header

(0) ShareShare
ReportReport
Posted on by 300

I am trying to import trade journals using OpenSalesPriceJournalLine

I understand I need to create a OpenTradeAgreementJournalHeaderV2 for my headers but I am getting exceptions when trying to create it.

The code below returns an exception " A null value was found for the property named 'JournalNumber', which has the expected type 'Edm.String[Nullable=False"

var header = new OpenTradeAgreementJournalHeaderV2()
{
DataAreaId = dataAreaId,
};

context.AddToOpenTradeAgreementJournalHeadersV2(header);

var headerResponse = context.SaveChanges();

Does anyone know why would I need to enter a journal number when I am trying to create a journal header and journal lines?

If I have to supply one myself from the third party app won't I risk creating two identical journal numbers?

If I do supply a Journal Number I get the following exception returned

TradeOpenTradeAgreementJournalHeaderV2Entity' for the following fields: JournalNumber, TradeAgreementJournalNameId. Infolog: Warning: Field 'Price/discount journal number' does not allow editing.; Warning: Invalid specification of Price/discount journal number; Warning: Number sequence Sale_306 does not allow change to a higher number.; Warning: Field 'Name' must be filled in.

Im confused about what this means, shouldn't D365 be creating journal numbers when the journal is created, like in Ax2012?

I have the same question (0)
  • Shaun Hawkshaw Profile Picture
    985 on at

    Hi there,

    When importing Trade agreements, I have used "TradeAgreementJOurnalTable" entity to get the header record in.

    The fields I used were: JournalNumber, DefaultTradeAgreementType, Journal description and TradeAgreementJournalNameID

  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,095 on at

    Hi Richerich79,

    Did you try to put empty value for JournalNumber?

    Take a look at post community.dynamics.com/.../generate-number-sequence-values-from-rest-services-and-odata

  • Suggested answer
    Rahul Mohta Profile Picture
    21,046 on at

    could possible make the number sequence manual for import and just align the format in import file

  • richierich79 Profile Picture
    300 on at

    @Sergi II set the Journal Number to empty string I get the following response.

    "Warning: Number  does not match format PDJ-#####.;"

    I could look at extending the entity in the link but would rather not if I could get away without doing so!

    @Shawn I think I have a knowledge gap as I can't see how I would create Ids for something that hasn't been created yet.

    Would you be able to share some code of how you created the journal to help?

    @Rahul Im using OData not an import file. The application is designed to be fully automated with no manual tasks

  • Sergei Minozhenko Profile Picture
    23,095 on at

    Hi Richerich79,

    How you fill fields in the header record? I quickly tried in my test project and i just fill DataAreaId and TradeAgreementJournalNameId and it works fine. Journal number is populated from number sequence.

  • richierich79 Profile Picture
    300 on at

    Hi Sergi. How do I get the value to populate TradeAgreementJournalNameId? I'm sorry, I don't know what this is.

    I am using 'USMF' as the dataareaId

  • Sergei Minozhenko Profile Picture
    23,095 on at

    Hi,

    When you create trade agreement journal manually you need to specify "Name" field from lookup (TradeAgreementJournalNameId is the same field on the entity).

    Related form in D365 is "Trage agreement journal names".

  • richierich79 Profile Picture
    300 on at

    Hi Sergi

    So when manually creating trade agreements I have values like "S_Price" and "S_Discount so I have rung the following code

     var header = new OpenTradeAgreementJournalHeaderV2()
    {
        DataAreaId = "USMF",
        TradeAgreementJournalNameId = "S_Price"
    };
    
    context.AddToOpenTradeAgreementJournalHeadersV2(header);
    
    var headerResponse = context.SaveChanges();

    But I get the following exception

    System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: A null value was found for the property named 'JournalNumber', which has the expected type 'Edm.String[Nullable=False'. The expected type 'Edm.String[Nullable=False' does not allow null values. at Microsoft.Dynamics.Platform.Integration.Services.OData.AxODataEntityDeserializer.ReadODataBody[T(HttpRequestMessage request) --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[ arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[ parameters, Object[ arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[ parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[ parameters) at Microsoft.Dynamics.Platform.Integration.Services.OData.AxODataEntityDeserializer.ReadODataBodyAsType(HttpRequestMessage request, Type clrType) at Microsoft.Dynamics.Platform.Integration.Services.OData.AxODataEntityDeserializer.ReadODataBodyAsDelta(HttpRequestMessage request, Type clrType) at Microsoft.Dynamics.Platform.Integration.Services.OData.AxODataController.ReadBodyAsDelta(EntityType entityType) at Microsoft.Dynamics.Platform.Integration.Services.OData.AxODataController.Post() at

    Is this the same test that you have attempted?

  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,095 on at

    Hi Rechierich79,

    Try to add SaveChangesOptions for SaveChanges method.

    SaveChanges(SaveChangesOptions.PostOnlySetProperties | SaveChangesOptions.BatchWithSingleChangeset)

  • richierich79 Profile Picture
    300 on at

    Hi Sergi

    I can only use SaveChanges option if I am using a DataServiceCollection, which I'm not (from the code snippet above)

    If I use the DataServiceCollection with and try to add OpenTradeAgreementJournalHeaderV2  to the collection I get the following exception

    An attempt to track an entity or complex type failed because the entity or complex type 'Microsoft.Dynamics.DataEntities.OpenTradeAgreementJournalHeaderV2' does not implement the INotifyPropertyChanged interface.'

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 660

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 655 Super User 2026 Season 1

#3
CP04-islander Profile Picture

CP04-islander 557

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans