CustomFieldValues.get_ItemFromSettingName issues  Topic is solved

Discussions relating to Jiwa 7 plugin development, and the Jiwa 7 API.

CustomFieldValues.get_ItemFromSettingName issues

Postby neil.interactit » Fri Nov 04, 2016 2:42 pm

Hey guys,

I'm a little stumped on this. I have a debtor maintenance plugin with the following:

Code: Select all
    public void Setup(IJiwaForm jiwaForm, Plugin plugin)
    {
        if (!(jiwaForm is frmDebtor)) return;
        _debtorForm = (frmDebtor)jiwaForm;
    }

    private string GetCustomValue(string key)
    {
        var customField = _debtorForm.Debtor.CustomFieldValues.get_ItemFromSettingName(key);
        return customField == null ? "" : customField.Contents;
    }

    private void SetCustomValue(string key, string value)
    {
        var customField = _debtorForm.Debtor.CustomFieldValues.get_ItemFromSettingName(key);
        if (customField != null) customField.Contents = value;
    }

Which all works a treat!

I have ported this to a cashbook plugin as follows:

Code: Select all
    public void Setup(IJiwaForm jiwaForm, Plugin plugin)
    {
        if (!(jiwaForm is frmCashBook)) return;
        _cashBookForm = (frmCashBook)jiwaForm;
    }

    private string GetCustomValue(string key)
    {
        var customField = _cashBookForm.CashBook.CustomFieldValues.get_ItemFromSettingName(key);
        return customField == null ? "" : customField.Contents;
    }

    private void SetCustomValue(string key, string value)
    {
        var customField = _cashBookForm.CashBook.CustomFieldValues.get_ItemFromSettingName(key);
        if (customField != null) customField.Contents = value;
    }

And it won't play ball! I cannot set a custom value. I have:
    confirmed that the custom fields are created in the plugin
    confirmed that the code is executing, including logging that "customField.Contents = value;" is firing
    confirmed that nothing is appearing in the database (CB_CustomSettingValues)

Can you point me in the right direction on this?

Cheers,
Neil.
neil.interactit
Kohai
Kohai
 
Posts: 232
Joined: Wed Dec 03, 2014 2:36 pm
Topics Solved: 6

Re: CustomFieldValues.get_ItemFromSettingName issues

Postby SBarnes » Fri Nov 04, 2016 10:59 pm

Hi Neil,

My only suggestion without trying out the code is that you could try setting or checking the value of the insert flag on a new entry and change flag if you can on an existing entry for the custom field itself.

The iSave on the custom field when it gets called like most Jiwa Collection Items looks at these flags to determine it it should do something.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: CustomFieldValues.get_ItemFromSettingName issues

Postby neil.interactit » Mon Nov 07, 2016 9:37 am

Thanks.

Checking directly after customField.Contents = value; shows both InsertFlag and ChangeFlag as true. But still nothing is appearing in the database.

Any further insight?

Cheers,
Neil
neil.interactit
Kohai
Kohai
 
Posts: 232
Joined: Wed Dec 03, 2014 2:36 pm
Topics Solved: 6

Re: CustomFieldValues.get_ItemFromSettingName issues

Postby SBarnes » Mon Nov 07, 2016 12:06 pm

Hi Neil,

My only other suggestions are to attach to the custom field collection events for before save and save end and see if the actual save on the collection is being called but I am pretty sure this will be the case, you could also try calling the CustomField.Save(); yourself and see if you end up with something in the database, if this ends up being the case then the problem then its because the collection thinks nothing has changed, it has a change flag also but its read only.

How you get around that at the moment I can't think of a way.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: CustomFieldValues.get_ItemFromSettingName issues  Topic is solved

Postby Mike.Sheen » Sun Nov 13, 2016 12:35 pm

Hi Neil,

I'm not able to reproduce this issue.

I've created a plugin for CashBook Receipts (attached) based on your code snippets - can you see if it behaves for you.

Mike
Attachments
Plugin Cashbook test custom settings.xml
Sample Plugin
(30.34 KiB) Downloaded 846 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: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: CustomFieldValues.get_ItemFromSettingName issues

Postby neil.interactit » Wed Nov 16, 2016 1:34 pm

Hi Mike,

OK, thanks. Looks like more a timing issue. Your test worked, so I added
Code: Select all
        ...
        _cashBookForm.CashBook.SaveStart += SaveStart;
    }

    private void SaveStart(object sender, EventArgs e)
    {
        SetCustomValue("Filter", Guid.NewGuid().ToString());
     }

to my plugin. This worked, whereas the other calls to SetCustomValue did not. I'll investigate further and possibly just invoke a push/pop stack which then executes in SaveStart.

Cheers,
Neil.
neil.interactit
Kohai
Kohai
 
Posts: 232
Joined: Wed Dec 03, 2014 2:36 pm
Topics Solved: 6

Re: CustomFieldValues.get_ItemFromSettingName issues

Postby neil.interactit » Wed Nov 16, 2016 3:36 pm

Yep, that did it.

For some reason SetCustomValue won't work triggered via a button click, but does work from SaveStart.

In case it helps, here's the implementation ...
Code: Select all
     Stack<Tuple<string, string>> _pendingCustomValues = new Stack<Tuple<string, string>>();
     private void SetCustomValue(string key, string value)
     {
         _pendingCustomValues.Push(new Tuple<string, string>(key, value));
     }
 
     private void SetCustomValuesNow()
     {
         while (_pendingCustomValues.Count > 0) SetCustomValueNow(_pendingCustomValues.Pop());
     }
 
     private void SetCustomValueNow(Tuple<string, string> tuple)
     {
         SetCustomValueNow(tuple.Item1, tuple.Item2);
     }
 
     private void SetCustomValueNow(string key, string value)
     {
         var customField = _cashBookForm.CashBook.CustomFieldValues.get_ItemFromSettingName(key);
         if (customField != null) customField.Contents = value;
     }
---------------------------------------------------------------------------
         ...
         _cashBookForm.CashBook.SaveStart  = SaveStart;
     }
 
     private void SaveStart(object sender, EventArgs e)
     {
         SetCustomValuesNow();
     }


Cheers,
Neil.
neil.interactit
Kohai
Kohai
 
Posts: 232
Joined: Wed Dec 03, 2014 2:36 pm
Topics Solved: 6


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 3 guests