Page 1 of 1

Add new Consignment Note

PostPosted: Wed Sep 28, 2022 10:26 am
by Ernst
DateError.jpg


JIWA 721..
Keep getting this date error, even though my consign date is formatted correctly. Is this the lastsaveddate giving a problem.

Any suggestions to try?

Code is.

If SalesOrderH.Carrier.ConsignmentNoteCollection.Count = 0 Then
Dim MyConsignNote As New JiwaFinancials.Jiwa.JiwaSales.SalesOrder.ConsignmentNote
MyConsignNote.ConsignmentNoteNo = "LUB" & SalesOrder.InvoiceNo & salesorder.CurrentHistoryNo
MyConsignNote.ConsignmentNoteDate = Date.Now
SalesOrderH.Carrier.ConsignmentNoteCollection.Add(MyConsignNote)
End If

Re: Add new Consignment Note  Topic is solved

PostPosted: Wed Sep 28, 2022 11:19 am
by SBarnes
For starters the con note is a collection item so you can't just new one up you should be using the factory to create one, below is code that works without complaint, it isn't exactly what you are looking for but is similar, I suspect you not using the factory is causing your issue


Code: Select all
List<ConsignmentNote> consignmentNotes = carrier.ConsignmentNoteCollection.Cast<ConsignmentNote>().ToList();
               ConsignmentNote foundConnote = consignmentNotes.FirstOrDefault(c => c.ConsignmentNoteNo == request.Connotenumber);
               if(foundConnote == null)
               {
                  foundConnote = manager.CollectionItemFactory.CreateCollectionItem<ConsignmentNote>();
                  carrier.ConsignmentNoteCollection.Add(foundConnote);
                  
               }
               foundConnote.ConsignmentNoteNo = request.Connotenumber;
               foundConnote.ConsignmentNoteDate = DateTime.Parse( request.Condate);
               
               foundConnote.ExGSTAmount = request.Rate;
               foundConnote.GSTAmount = request.Gstamount;

Re: Add new Consignment Note

PostPosted: Wed Sep 28, 2022 4:08 pm
by Ernst
Thanks Stuart, eventually got it working with this piece of VB code, the C# does not convert to VB very well.

Thanks for the help.

If SalesOrderH.Carrier.ConsignmentNoteCollection.Count = 0 Then

Dim MyConsignNote As New JiwaFinancials.Jiwa.JiwaSales.SalesOrder.ConsignmentNote
MyConsignNote = Salesorder.Manager.CollectionItemFactory.CreateCollectionItem(Of JiwaFinancials.Jiwa.JiwaSales.SalesOrder.ConsignmentNote)
SalesOrderH.Carrier.ConsignmentNoteCollection.Add(MyConsignNote)
MyConsignNote.ConsignmentNoteNo = "LUB" & SalesOrder.InvoiceNo & salesorder.CurrentHistoryNo
MyConsignNote.ConsignmentNoteDate = Date.Now

End If

Re: Add new Consignment Note

PostPosted: Wed Sep 28, 2022 4:15 pm
by Mike.Sheen
You should modify this line

Code: Select all
         Dim MyConsignNote As New JiwaFinancials.Jiwa.JiwaSales.SalesOrder.ConsignmentNote


to not NEW, just declare:

Code: Select all
         Dim MyConsignNote As JiwaFinancials.Jiwa.JiwaSales.SalesOrder.ConsignmentNote


New-ing is pointless, as the next line uses the factory to obtain a new instance of the ConsignmentNote:

Code: Select all
         MyConsignNote = Salesorder.Manager.CollectionItemFactory.CreateCollectionItem(Of JiwaFinancials.Jiwa.JiwaSales.SalesOrder.ConsignmentNote)


What CollectionItemFactory.CreateCollectionItem does for you is the new-ing and setting of the Manager class and other stuff - it returns a new-ed instance of the type requested.

As for conversion - I don't see any glaring issues with converted code:
ConvertedCode.png

Re: Add new Consignment Note

PostPosted: Wed Sep 28, 2022 6:48 pm
by SBarnes
eventually got it working with this piece of VB code, the C# does not convert to VB very well.


Ah another reason in favour for just going with c# :lol:

Seriously though happy you got it going in the end, happy to help.

Re: Add new Consignment Note

PostPosted: Thu Oct 06, 2022 12:56 pm
by Ernst
Thanks Mike have removed the New.

These are all the lovely errors, when you try and compile the converted VB,

Capture3.PNG
Capture3.PNG (42.91 KiB) Viewed 1017 times

Re: Add new Consignment Note

PostPosted: Thu Oct 06, 2022 12:58 pm
by Mike.Sheen
Ernst wrote:Thanks Mike have removed the New.

These are all the lovely errors, when you try and compile the converted VB,

Capture3.PNG


You're just missing a few using statements. 2 or 3 usings and that'll clear right up.

Or fully namespace the types in question.

Re: Add new Consignment Note

PostPosted: Thu Oct 06, 2022 1:01 pm
by SBarnes
And the error about request is due to the fact that the sample code came from a REST api plugin