Page 1 of 1

Creating a note by the current user

PostPosted: Thu Feb 16, 2017 4:50 pm
by neil.interactit
Hey guys,

No doubt I'm missing the obvious somewhere. I need to create a note by the current user ...

Code: Select all
        var note = new Note() { NoteText = "MY NOTE TEXT", LastModifiedByStaffMember = Manager.Instance.Staff, LastSavedDateTime = DateTime.Now, NoteType = _creditorForm.Creditor.Notes.DefaultNoteType };
        _creditorForm.Creditor.Notes.Add(note);

But I cannot implicitly convert type 'JiwaFinancials.Jiwa.JiwaApplication.JiwaStaff.clsStaff' to 'JiwaFinancials.Jiwa.JiwaApplication.Entities.Staff.Staff'. How do I get the Entity.Staff of the current user?

Cheers,
Neil.

Re: Creating a note by the current user  Topic is solved

PostPosted: Thu Feb 16, 2017 4:59 pm
by Mike.Sheen
The long way is to create an new instance of a JiwaApplication.Entities.Staff.Staff and do a .ReadRecord, passing in the Manager.Instance.Staff.RecID, then set LastModifiedByStaffMember to be that entity.

For example:

Code: Select all
var staff = new JiwaApplication.Entities.Staff.Staff();
staff.ReadRecord(Manager.Instance.Staff.RecID);
var note = new Note() { NoteText = "MY NOTE TEXT", LastModifiedByStaffMember = staff, LastSavedDateTime = DateTime.Now, NoteType = _creditorForm.Creditor.Notes.DefaultNoteType };
_creditorForm.Creditor.Notes.Add(note);

Re: Creating a note by the current user

PostPosted: Mon Feb 20, 2017 9:17 am
by neil.interactit
Easy! Many thanks Mike.

Cheers,
Neil

Re: Creating a note by the current user

PostPosted: Thu Oct 10, 2019 9:47 am
by neil.interactit
Hi Mike,

Code: Select all
_creditorForm.Creditor.Notes.DefaultNoteType

appears to be depreciated in 7.2.1, and I can't spot what to migrate to, could you advise?

Cheers,
Neil

Re: Creating a note by the current user

PostPosted: Thu Oct 10, 2019 6:50 pm
by SBarnes
Hi Neil,

Mike or Scott might give you an easier option but this should work, if you use JiwaFinancials.Jiwa.JiwaApplication.Notes.NoteTypeCollection and call read after setting the notetype (its a string) to "JiwaFinancials.Jiwa.JiwaCreditors.Creditor" that will give you all the note types for creditors and then there is a function on the collection called GetDefaultNoteType which will give you the default.

Re: Creating a note by the current user

PostPosted: Fri Oct 11, 2019 11:00 am
by neil.interactit
Thanks Stuart,

Sweet ...

Code: Select all
var defaultNoteType = new NoteTypeCollection { NoteType = "JiwaFinancials.Jiwa.JiwaCreditors.Creditor" }.GetDefaultNoteType();

Many thanks.

Re: Creating a note by the current user

PostPosted: Fri Oct 11, 2019 2:38 pm
by Scott.Pearce
Code: Select all
var defaultNoteType = new NoteTypeCollection { NoteType = "JiwaFinancials.Jiwa.JiwaCreditors.Creditor" }.GetDefaultNoteType();


Make sure you use a factory when creating Jiwa objects, or you may have problems. Plus, I don't see you reading in the above code, so you won't get anything back.

Here's the code I would use (untested):

Code: Select all
var noteTypes = Manager.CollectionFactory.CreateCollection<NoteTypeCollection, NoteType>();
noteTypes.NoteType = "JiwaFinancials.Jiwa.JiwaCreditors.Creditor";
noteTypes.Read();
var defaultNoteType = noteTypes.GetDefaultNoteType();

Re: Creating a note by the current user

PostPosted: Fri Oct 11, 2019 2:40 pm
by Mike.Sheen
Why do you need the default note type anyway? If you add a new note, if you don't specify the note type, it will set the note type to be the default for you anyway.