Page 1 of 2

Importing Notes

PostPosted: Fri Feb 23, 2018 11:18 am
by Ernst
We found the JIWA7 plugin Plugin Inventory Import Notes, very useful, but its in C# Grrrrr.

Is it possible to make it update the existing Note rather than adding a new one. Or delete the existing before adding.

We have a whole bunch of Notes, Like Keyword/ Extended Description, which point to things on the web pages, so we dont want a new note, just update the exisiting Note, we have clicked the Update only button on the Import.

This is JIWA 7.0.175

Re: Importing Notes  Topic is solved

PostPosted: Sat Feb 24, 2018 1:19 pm
by Mike.Sheen
Ernst wrote:We found the JIWA7 plugin Plugin Inventory Import Notes, very useful

Damn! I knew adding it as part of the upgrade and enabling it - as well as documenting it in the version documentation would make it too easy to find!

Ernst wrote:but its in C# Grrrrr.


I've shown you before a way to convert from C# to VB.NET - does that not work for you?

Ernst wrote:Is it possible to make it update the existing Note rather than adding a new one. Or delete the existing before adding.

We have a whole bunch of Notes, Like Keyword/ Extended Description, which point to things on the web pages, so we dont want a new note, just update the exisiting Note, we have clicked the Update only button on the Import.

This is JIWA 7.0.175


Yes, certainly possible - depending on your rules.
If you were to say that an inventory item can only have one note per notetype, then the attached plugin will do this (make sure you disable the standard plugin "Inventory Import Notes" before enabling and using this one).
Plugin Inventory Import Notes - Update existing.xml
Modified plugin
(34 KiB) Downloaded 128 times


If you have more complex rules (like yes, some notetypes are allowed to be added to the same item multiple times) then we'll need to know how we decide if it is an update or a new note. Providing the NoteID in the import file is probably the easiest way - but what I've given you should be at enough to help you along to implement such rules.

The plugin attached changed lines 112-119 from:
Code: Select all
JiwaFinancials.Jiwa.JiwaApplication.Notes.Note note = new JiwaFinancials.Jiwa.JiwaApplication.Notes.Note();

if (noteType != null) {
   note.NoteType = noteType;
}

note.NoteText = noteText;
Inventory.Notes.Add(note);


To:
Code: Select all
// Update for Ernst as per https://forums.jiwa.com.au/viewtopic.php?f=26&t=908
// Only add a note if no existing note type found - if one is found, update the note text instead of adding a new one.

// Is there an existing note for this item with the same note type?
JiwaFinancials.Jiwa.JiwaApplication.Notes.Note existingNote = Inventory.Notes.Cast<JiwaFinancials.Jiwa.JiwaApplication.Notes.Note>().FirstOrDefault(x => noteType != null && x.NoteType.RecID == noteType.RecID);
if(existingNote == null)
{
   JiwaFinancials.Jiwa.JiwaApplication.Notes.Note note = new JiwaFinancials.Jiwa.JiwaApplication.Notes.Note();
   if (noteType != null) {
      note.NoteType = noteType;
   }

   note.NoteText = noteText;
   Inventory.Notes.Add(note);
}
else
   existingNote.NoteText = noteText;


Mike

Re: Importing Notes

PostPosted: Sat Feb 24, 2018 5:57 pm
by SBarnes
Hi Mike,

I have seen examples where Telerik's online converter won't parse the code, and there doesn't seem to be a reason why, it can fail for a small amount of code and not have problem with a huge amount.

In this case I have either had to do it by hand if its a small amount of code or the other option that works is to load the code into Jiwa as an enabled plugin and use either Telerik's Just Decompile or Redgate's .net Relfector to open the DLL for the plugin, a bit more convoluted but it works and for large amounts of code and actually formats things better and you can flick between both languages easily.

Re: Importing Notes

PostPosted: Sat Feb 24, 2018 6:43 pm
by Mike.Sheen
SBarnes wrote:Hi Mike,

I have seen examples where Telerik's online converter won't parse the code, and there doesn't seem to be a reason why, it can fail for a small amount of code and not have problem with a huge amount.

In this case I have either had to do it by hand if its a small amount of code or the other option that works is to load the code into Jiwa as an enabled plugin and use either Telerik's Just Decompile or Redgate's .net Relfector to open the DLL for the plugin, a bit more convoluted but it works and for large amounts of code and actually formats things better and you can flick between both languages easily.


I normally do it by hand also - and in doing so find a few things I want to "improve" along the way.

For the plugin I provided in C# above, I tried it out with the Telerik online converter and it converted it without issue - but I did need to make some changes before it would compile. Perhaps I was lucky :)

I just had to add the Implements after each method in the classes implementing an interface.

For instance, in the converted code - in the FormPlugin class:
Code: Select all
Public Sub SetupBeforeHandlers(ByVal JiwaForm As JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm, ByVal Plugin As JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin)


Just had to be changed to:
Code: Select all
Public Sub SetupBeforeHandlers(ByVal JiwaForm As JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm, ByVal Plugin As JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin) Implements JiwaFinancials.Jiwa.JiwaApplication.IJiwaFormPlugin.SetupBeforeHandlers


Ernst - the attached might be more to your taste! But note the suggestion by Stuart to try alternate means to convert C# code to VB.NET for future reference.
Plugin Inventory Import Notes - Update existing VB.NET.xml
VB.NET version by Telerik
(35.88 KiB) Downloaded 110 times

Re: Importing Notes

PostPosted: Sun Feb 25, 2018 7:37 pm
by Ernst
Thanks for your comprehensive reply, Mike, will test it out at the customer this week... :) :D :P

Re: Importing Notes

PostPosted: Fri Apr 20, 2018 11:57 am
by Ernst
Thanks we just got that tested and working. Client very Happy, Will follow up on that VB convertor.

Re: Importing Notes

PostPosted: Fri Jul 19, 2019 8:18 pm
by Ernst
Having trouble converting this line to 7.02.01

JiwaFinancials.Jiwa.JiwaApplication.Notes.Note existingNote = Inventory.Notes.Cast<JiwaFinancials.Jiwa.JiwaApplication.Notes.Note>().FirstOrDefault(x => noteType != null && x.NoteType.RecID == noteType.RecID);


Seems there is no .Cast in 7.02.01. What should I use in its place....

Thanks..for the help.

Re: Importing Notes

PostPosted: Fri Jul 19, 2019 8:49 pm
by SBarnes
If you have the recid of the note
Code: Select all
JiwaFinancials.Jiwa.JiwaApplication.Notes.NoteCollection notes = inventory.Notes;
JiwaFinancials.Jiwa.JiwaApplication.Notes.Note note = notes[recid];


Not quite one line but this should do it also if the above doesn't work for you and you are going off the note type

Code: Select all
            JiwaFinancials.Jiwa.JiwaApplication.Notes.NoteCollection notes = inventory.Notes;
            foreach(JiwaFinancials.Jiwa.JiwaApplication.Notes.Note note in notes)
            {
               if (note.NoteType == recid)
               {
                  existingnote = note;
                  break;
               }
            }

Re: Importing Notes

PostPosted: Fri Jul 19, 2019 9:37 pm
by pricerc
Ernst wrote:Seems there is no .Cast in 7.02.01. What should I use in its place....


.Cast<T> is part of the .NET framework; it's not a JIWA function. It's in the System,Linq namespace; you may need to add a reference to System.Linq.DLL.

https://docs.microsoft.com/en-us/dotnet/api/system.linq.enumerable.cast?view=netframework-4.8

Re: Importing Notes

PostPosted: Fri Jul 19, 2019 9:46 pm
by Ernst
Thanks, Gave me some ideas. Needed some extras to get it to compile...Hope it works..

Darn c.. Case sensitive.. how insensitive....:) and double = is = whyyyy

bool found2 = false;
JiwaFinancials.Jiwa.JiwaApplication.Notes.NoteCollection notes = Inventory.Notes;
foreach(JiwaFinancials.Jiwa.JiwaApplication.Notes.Note note in notes)
{
if (note.NoteType == noteType)
{
note.NoteText = noteText;
found2 = true;
}
}
// if(existingNote == null)
if (found2 == false)
{
JiwaFinancials.Jiwa.JiwaApplication.Notes.Note note = Inventory.Manager.CollectionItemFactory.CreateCollectionItem<JiwaFinancials.Jiwa.JiwaApplication.Notes.Note>();

if (noteType != null) {
note.NoteType = noteType;
}

note.NoteText = noteText;
Inventory.Notes.Add(note);
}
// else
// existingNote.NoteText = noteText;


}