Page 1 of 1

CustomFieldValues.get_ItemFromSettingName issues

PostPosted: Fri Nov 04, 2016 2:42 pm
by neil.interactit
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.

Re: CustomFieldValues.get_ItemFromSettingName issues

PostPosted: Fri Nov 04, 2016 10:59 pm
by SBarnes
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.

Re: CustomFieldValues.get_ItemFromSettingName issues

PostPosted: Mon Nov 07, 2016 9:37 am
by neil.interactit
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

Re: CustomFieldValues.get_ItemFromSettingName issues

PostPosted: Mon Nov 07, 2016 12:06 pm
by SBarnes
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.

Re: CustomFieldValues.get_ItemFromSettingName issues  Topic is solved

PostPosted: Sun Nov 13, 2016 12:35 pm
by Mike.Sheen
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

Re: CustomFieldValues.get_ItemFromSettingName issues

PostPosted: Wed Nov 16, 2016 1:34 pm
by neil.interactit
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.

Re: CustomFieldValues.get_ItemFromSettingName issues

PostPosted: Wed Nov 16, 2016 3:36 pm
by neil.interactit
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.