salesOrderPOSTRequest

Discussions relating to the REST API of Jiwa 7.

salesOrderPOSTRequest

Postby tyeatman » Tue May 12, 2020 5:16 pm

Hi

I am uploading orders through the Rest API, and are wanting to add Notes to the order.

I have seen the examples to add a Note to a Sales Order, but are unable to see how to specify the NoteType using the NoteTypeID.

Example of what I have so far using the ServiceStack Client.

salesOrderPOSTRequest.Notes.Add(new JiwaFinancials.Jiwa.JiwaServiceModel.Notes.Note()
{
NoteType = ????????? ,
NoteText = strComment.ToString()});
}

Thank you for your help.

Tony
tyeatman
I'm new here
I'm new here
 
Posts: 6
Joined: Tue Aug 15, 2017 12:04 pm

Re: salesOrderPOSTRequest

Postby SBarnes » Tue May 12, 2020 10:11 pm

See https://api.jiwa.com.au/json/metadata?o ... anyRequest this will give the available Note types for a sales order, you may also find by not setting the type it will automatically set it to the default note type but without checking the code I can't say with 100% surety.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1618
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: salesOrderPOSTRequest

Postby Mike.Sheen » Tue May 12, 2020 10:19 pm

SBarnes wrote:See https://api.jiwa.com.au/json/metadata?o ... anyRequest this will give the available Note types for a sales order, you may also find by not setting the type it will automatically set it to the default note type but without checking the code I can't say with 100% surety.


Yep.

So, you can omit the NoteType to get the default, or if you want a specific one, provide it - like this:

Code: Select all
salesOrderPOSTRequest.Notes.Add(new JiwaFinancials.Jiwa.JiwaServiceModel.Notes.Note()
{
NoteType = new JiwaFinancials.Jiwa.JiwaServiceModel.Notes.NoteType() { NoteTypeID = "????????????"} ,
NoteText = strComment.ToString()});
}


I'd have to check but I think you can also just provide the description instead of the NoteTypeID, and we'll try to resolve it that way. - yes, you can omit the NoteTypeID and use description instead.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: salesOrderPOSTRequest

Postby tyeatman » Wed May 13, 2020 8:55 am

Thank you for the responses.

I have used your solution below, and the note is still being created with the default note type.

Code: Select all
salesOrderPOSTRequest.Notes.Add(new JiwaFinancials.Jiwa.JiwaServiceModel.Notes.Note()
                {
                    NoteType = new JiwaFinancials.Jiwa.JiwaServiceModel.Notes.NoteType() { NoteTypeID = "0dc3cf6d-92eb-4854-8548-52275034e350" },
                    NoteText = strComment.ToString()});   


If I try it with {Description = "My Note Description"} it errors when making the Order post request with 'Object variable or With block variable not set

Tony
tyeatman
I'm new here
I'm new here
 
Posts: 6
Joined: Tue Aug 15, 2017 12:04 pm

Re: salesOrderPOSTRequest

Postby SBarnes » Wed May 13, 2020 9:20 am

I've had a look at the code that deserialises the note it will definitely try and find a match on the type id or type description as Mike said, without seeing the code in its entirety that is sending the request it's difficult to comment further.

One thing you could do is look at the request logs and see what the api is actually receiving.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1618
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: salesOrderPOSTRequest

Postby Mike.Sheen » Wed May 13, 2020 6:26 pm

tyeatman wrote:Thank you for the responses.

I have used your solution below, and the note is still being created with the default note type.

Code: Select all
salesOrderPOSTRequest.Notes.Add(new JiwaFinancials.Jiwa.JiwaServiceModel.Notes.Note()
                {
                    NoteType = new JiwaFinancials.Jiwa.JiwaServiceModel.Notes.NoteType() { NoteTypeID = "0dc3cf6d-92eb-4854-8548-52275034e350" },
                    NoteText = strComment.ToString()});   


If I try it with {Description = "My Note Description"} it errors when making the Order post request with 'Object variable or With block variable not set

Tony


Ok, so I found a bug when using the Description for the NoteType instead of the NoteTypeID - it produces the error as you describe. The logic does try to resolve the NoteType with the Description if NoteTypeID is provided, but it incorrectly then tried to compare NoteTypeID in the DTO with the Description of known notes, which caused the exception.

Logged as DEV-8233.

Providing the NoteTypeID instead should still work - if it saves using the default NoteType instead, then it has to be because it does not receive a NoteType in the DTO, or that part of the DTO does not have a NoteTypeID in it.

Below is the code we use to deserialise a Note when we're POSTing or PATCHing notes everywhere - it's the same code for sales orders, inventory, and everywhere else which has notes (still has the erroneous attempt to get a NoteType using NoteTypeID instead of Description if NoteTypeID is not provided).

Code: Select all
Public Sub DTO_Deserialise(ByVal Note As JiwaServiceModel.Notes.Note) Implements IJiwaDTODeserialisable(Of JiwaServiceModel.Notes.Note).DTO_Deserialise
   OnDTODeserialiseStart(Note)

   If Note.NoteText IsNot Nothing Then
      NoteText = Note.NoteText
   End If

   If Note.LineNo IsNot Nothing Then
      ItemNo = Note.LineNo
   End If

   If Note.LastSavedDateTime IsNot Nothing Then
      LastSavedDateTime = Note.LastSavedDateTime
   End If

   If Note.NoteType IsNot Nothing Then
      Dim noteType As JiwaApplication.Notes.NoteType = Nothing

      If Note.NoteType.NoteTypeID IsNot Nothing AndAlso Note.NoteType.NoteTypeID.Trim.Length > 0 Then
         noteType = NoteCollection.NoteTypeCollection.Item(Note.NoteType.NoteTypeID)

         If noteType Is Nothing Then
            Throw New JiwaApplication.Exceptions.RecordNotFoundException(String.Format("NoteType with RecID '{0}' was not found.", Note.NoteType.NoteTypeID))
         End If

         Me.NoteType = noteType
      ElseIf Note.NoteType.Description IsNot Nothing Then
         noteType = NoteCollection.NoteTypeCollection.GetItem("Description", Note.NoteType.NoteTypeID)

         If noteType Is Nothing Then
            Throw New JiwaApplication.Exceptions.RecordNotFoundException(String.Format("NoteType with Description '{0}' was not found.", Note.NoteType.Description))
         End If

         Me.NoteType = noteType
      End If
   End If

   If Note.LastModifiedByStaffID IsNot Nothing AndAlso Note.LastModifiedByStaffID.Trim.Length > 0 Then
      Me.LastModifiedByStaffMember.ReadRecord(Note.LastModifiedByStaffID)
   ElseIf Note.LastModifiedByStaffUsername IsNot Nothing AndAlso Note.LastModifiedByStaffUsername.Trim.Length > 0 Then
      Me.LastModifiedByStaffMember.ReadRecordByUsername(Note.LastModifiedByStaffUsername)
   End If

   OnDTODeserialiseEnd(Note)
End Sub


If you have defined any request filters, they might be stripping stuff out - but if not then perhaps a custom plugin or something is overriding your note type?
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: salesOrderPOSTRequest

Postby tyeatman » Thu May 14, 2020 9:11 am

Thank you for your replies and assistance.

I am not applying any filters to the post (I am creating a sales order), and there are no plugins relating to notes.

From the code you posted, I can see that an error is generated if the NoteTypeID is not found, I tested this, and it will throw an error if an invalid NotTypeID is supplied.

This would suggest that it is finding the NoteTypeID I am supplying, but is it being used in the procedure that writes the record to the table?

Tony
tyeatman
I'm new here
I'm new here
 
Posts: 6
Joined: Tue Aug 15, 2017 12:04 pm

Re: salesOrderPOSTRequest

Postby SBarnes » Thu May 14, 2020 9:37 am

Hi Tony,

Without seeing the full code both Mike and I are are making educated guesses as to the source of the issue what I would suggest you do is the following:

1. Create a Jiwa demo database and see if you get the error there that will at least determine if the issue is coming from the client code and not something on the database itself.
2. If you get the error on a demo database and have visual studio installed find the code that performs the request in the Rest Api plugin and add the line System.Diagnostics.Debugger.Launch(); near the top
3. Save the plugin and restart the web api, when you make the request you should see it will give you the opportunity to launch visual studio as the JIT Debugger and then you will be able to see exactly what is being passed in and what is going on.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1618
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: salesOrderPOSTRequest

Postby tyeatman » Thu May 21, 2020 2:17 pm

Thank you for the tip regarding being able to debug.

As everything else is working well, and I have to get this working, I am in the interim writing the Note data directly to the table.

I will come back to this when the time allows.
tyeatman
I'm new here
I'm new here
 
Posts: 6
Joined: Tue Aug 15, 2017 12:04 pm

Re: salesOrderPOSTRequest

Postby SBarnes » Thu May 21, 2020 2:53 pm

Writing to the table directly is something to try and avoid, attached is something that may help which is related to debtor notes when there was a bug a while back, basically there are serialise/deserialise events that you can attach to, the plugin attached was designed to get around the fact that fields were not being set correctly on debtor notes.
Attachments
Plugin Deserialise Debtor Note fix Last Modified.xml
(33.16 KiB) Downloaded 57 times
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1618
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Next

Return to REST API

Who is online

Users browsing this forum: No registered users and 1 guest

cron