Importing Notes  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Importing Notes

Postby Ernst » Fri Feb 23, 2018 11:18 am

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
Attachments
Plugin Inventory Import Notes.xml
(32.25 KiB) Downloaded 102 times
User avatar
Ernst
Kohai
Kohai
 
Posts: 219
Joined: Tue Feb 19, 2008 3:43 pm
Topics Solved: 12

Re: Importing Notes  Topic is solved

Postby Mike.Sheen » Sat Feb 24, 2018 1:19 pm

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 116 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
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: Importing Notes

Postby SBarnes » Sat Feb 24, 2018 5:57 pm

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.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1618
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Importing Notes

Postby Mike.Sheen » Sat Feb 24, 2018 6:43 pm

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 95 times
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: Importing Notes

Postby Ernst » Sun Feb 25, 2018 7:37 pm

Thanks for your comprehensive reply, Mike, will test it out at the customer this week... :) :D :P
User avatar
Ernst
Kohai
Kohai
 
Posts: 219
Joined: Tue Feb 19, 2008 3:43 pm
Topics Solved: 12

Re: Importing Notes

Postby Ernst » Fri Apr 20, 2018 11:57 am

Thanks we just got that tested and working. Client very Happy, Will follow up on that VB convertor.
User avatar
Ernst
Kohai
Kohai
 
Posts: 219
Joined: Tue Feb 19, 2008 3:43 pm
Topics Solved: 12

Re: Importing Notes

Postby Ernst » Fri Jul 19, 2019 8:18 pm

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.
User avatar
Ernst
Kohai
Kohai
 
Posts: 219
Joined: Tue Feb 19, 2008 3:43 pm
Topics Solved: 12

Re: Importing Notes

Postby SBarnes » Fri Jul 19, 2019 8:49 pm

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;
               }
            }
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1618
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Importing Notes

Postby pricerc » Fri Jul 19, 2019 9:37 pm

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
/Ryan

ERP Consultant,
Advanced ERP Limited, NZ
https://aerp.co.nz
User avatar
pricerc
Senpai
Senpai
 
Posts: 504
Joined: Mon Aug 10, 2009 12:22 pm
Location: Auckland, NZ
Topics Solved: 20

Re: Importing Notes

Postby Ernst » Fri Jul 19, 2019 9:46 pm

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;


}
User avatar
Ernst
Kohai
Kohai
 
Posts: 219
Joined: Tue Feb 19, 2008 3:43 pm
Topics Solved: 12

Next

Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 7 guests