Custom column values getting erased  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Custom column values getting erased

Postby neil.interactit » Mon May 28, 2018 10:21 am

Hey guys,

I have a mystery gremlin blanking values in a custom column, that I can't track down.

To replicate, add a new C# plugin, paste in the code attached, add form reference JiwaFinancials.Jiwa.JiwaCRBatchTXUI.CreditorPurchases, restart. Add a new creditor purchase, add a line item, save, add a CRN value, save. You can now close/reopen the form and see the CRN value persisted.

Now add a second line item. Note the CRN value is erased (without any call to CRBatchTransObject_CreateReadEnd).

I'm stumped. Can you advise how to rectify this?

(Note the really dodgy persistence in the attached sample code ... I extracted a minimal sample from more extensive code and stripped out the database persistence)

Cheers,
Neil
Attachments
Creditor Purchases - BPay - TEST.zip
(1.59 KiB) Downloaded 82 times
neil.interactit
Kohai
Kohai
 
Posts: 227
Joined: Wed Dec 03, 2014 2:36 pm
Topics Solved: 6

Re: Custom column values getting erased

Postby Scott.Pearce » Mon May 28, 2018 10:31 am

I'll begin by suggesting you use a "Creditor Purchase Lines" custom field instead. This sidesteps the issue and means I don't have to debug it ;) Let me know if the custom field will suffice.
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 742
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 221

Re: Custom column values getting erased

Postby neil.interactit » Mon May 28, 2018 10:39 am

Could you send a demo code snippet ... I saw the CRBatchTransObject.LineCustomFields property, poked around the forum, but couldn't spot how to implement.
neil.interactit
Kohai
Kohai
 
Posts: 227
Joined: Wed Dec 03, 2014 2:36 pm
Topics Solved: 6

Re: Custom column values getting erased

Postby Scott.Pearce » Mon May 28, 2018 11:29 am

If you simply define one in the "Custom Fields" tab of the plugin, and then restart Jiwa, you will see the field magically appear on the Creditor Purchases lines grid. All the reading and saving of the custom field value is done for you.

I've attached a plugin that shows how to retrieve a line custom field value using code. In the example, a line custom field called "My CRN" is created on the Creditor Purchases lines grid. When a line is edited a message box is displayed showing the value for "My CRN" for that line.

Handler added:

Code: Select all
        public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm jiwaForm, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin plugin)
        {
            if (!(jiwaForm is CreditorCreditAdjustment || jiwaForm is CreditorDebitAdjustment || jiwaForm is CreditorPayment || jiwaForm is CreditorPurchases)) return;
            var form = (CRBatchTXPurchases)jiwaForm;
            AddColumnCrn(form);
         
         form.CRBatchTransObject.TransLines.DispersalChanged += CRBatchTransObject_TransLines_DispersalChanged;
        }


Code that retrieves and displays the line custom field value:

Code: Select all
      public void CRBatchTransObject_TransLines_DispersalChanged(JiwaFinancials.Jiwa.JiwaCRBatchTX.CRBatchDispersal item, System.ComponentModel.PropertyChangedEventArgs e)
      {      
         //Find the custom field value
         JiwaFinancials.Jiwa.JiwaApplication.CustomFields.CustomFieldValue customFieldValue = item.CustomFieldValues.get_ItemFromSettingName("My CRN","Custom Field Demo");
         
         //Display a message if a custom field value exists
         if (customFieldValue != null && customFieldValue.Contents != null)
            System.Windows.Forms.MessageBox.Show(string.Format("Value of {0}: {1}",customFieldValue.CustomField.PluginCustomField.Name, customFieldValue.Contents));
         
      }


Notes:
1. C# will not intelli-sense the get_ItemFromSettingName method (because it is a property with 2 parameters which c# does not like). The alternative to making a call to get_ItemFromSettingName would be to simply iterate through the collection and matching on CustomFieldValue.CustomField.PluginCustomField.Name thus:

Code: Select all
                Dim myCustomFieldValue  as JiwaFinancials.Jiwa.JiwaApplication.CustomFields.CustomFieldValue = nothing;
                For Each CustomFieldValue As CustomFieldValue In Me
                    If CustomFieldValue.CustomField.PluginCustomField.Name = SettingName AndAlso CustomFieldValue.CustomField.PluginCustomField.CustomFieldCollection.Plugin.Name = PluginName Then
                        myCustomFieldValue  = CustomFieldValue
                        exit for
                    End If
                Next


2. The creditor purchases batch object is a bit of an ugly duckling - a dispersal collection sits under each line. What you see on the grid isn't really a line, but a dispersal. This is why the line custom field collection hangs off the dispersal class.

3. To *modify* the line custom field value in code, simply push a value into customFieldValue.Contents. It will be saved away to the database when the Creditor Purchase object is saved.

4. Note that there is a difference between a Custom Field collection and a Custom Field *Value* collection.
Attachments
Plugin Custom Field Demo.xml
(33.69 KiB) Downloaded 95 times
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 742
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 221

Re: Custom column values getting erased

Postby neil.interactit » Mon May 28, 2018 6:09 pm

Thanks Scott.

The custom column ... too easy [head thump!]

Any chance of a code snippet showing accessing line custom values from the form object? I need to enable/disable activate based on business logic around values being required for certain creditors. So I need to access the custom values from form.CRBatchTransObject.ReadEnd ...

Code: Select all
            form.CRBatchTransObject.ReadEnd += (sender, e) => EnableActivate(form);
        }

        private static void EnableActivate(CRBatchTXPurchases form)
        {
            if (form.CRBatchTransObject.BatchStatus == CreditorBatchTrans.BatchStatusTypes.Activated) return;
            // access and check custom line items here
        }


And BTW, I can't download your attached zip ... I get
General Error
SQL ERROR [ mysql4 ]
Data too long for column 'ip' at row 1 [1406]
INSERT INTO download_log(attach_id, user_id, datetime, ip) VALUES(672, 620, NOW(), '2a01:44c8:5320:3405:c65e:51bb:d01e:1fbc')
(I guess my PC is supplying IPV6)

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

Re: Custom column values getting erased

Postby Mike.Sheen » Mon May 28, 2018 6:12 pm

neil.interactit wrote:And BTW, I can't download your attached zip ... I get
General Error
SQL ERROR [ mysql4 ]
Data too long for column 'ip' at row 1 [1406]
INSERT INTO download_log(attach_id, user_id, datetime, ip) VALUES(672, 620, NOW(), '2a01:44c8:5320:3405:c65e:51bb:d01e:1fbc')
(I guess my PC is supplying IPV6)


This should be fixed - can you try again?
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: Custom column values getting erased

Postby neil.interactit » Tue May 29, 2018 9:06 am

Downloads OK now, thanks Mike.
neil.interactit
Kohai
Kohai
 
Posts: 227
Joined: Wed Dec 03, 2014 2:36 pm
Topics Solved: 6

Re: Custom column values getting erased

Postby neil.interactit » Wed May 30, 2018 9:25 am

Bump. I can't quite see how to iterate through the CustomFieldValues from the CRBatchTXPurchases form object. Any advice appreciated.
neil.interactit
Kohai
Kohai
 
Posts: 227
Joined: Wed Dec 03, 2014 2:36 pm
Topics Solved: 6

Re: Custom column values getting erased  Topic is solved

Postby Scott.Pearce » Thu May 31, 2018 9:51 am

neil.interactit wrote:I can't quite see how to iterate through the CustomFieldValues from the CRBatchTXPurchases form object


The form object has a business logic object. The custom field values are in the business logic object.

Code: Select all
        private static void EnableActivate(CRBatchTXPurchases form)
        {
            if (form.CRBatchTransObject.BatchStatus == CreditorBatchTrans.BatchStatusTypes.Activated) return;
            // access and check custom line items here
         JiwaFinancials.Jiwa.JiwaCRBatchTX.CreditorBatchTrans creditorPurchasesBatch = (JiwaFinancials.Jiwa.JiwaCRBatchTX.CreditorBatchTrans)form.CRBatchTransObject;
         foreach(JiwaFinancials.Jiwa.JiwaCRBatchTX.CRBatchTranLine existingLine in creditorPurchasesBatch.TransLines)
         {
            foreach (JiwaFinancials.Jiwa.JiwaCRBatchTX.CRBatchDispersal existingDispersal in existingLine.Dispersals)
            {
               foreach(JiwaFinancials.Jiwa.JiwaApplication.CustomFields.CustomFieldValue existingCustomFieldValue in existingDispersal.CustomFieldValues)
               {
                  if(existingCustomFieldValue.CustomField.PluginCustomField.Name == "My CRN" && existingCustomFieldValue.CustomField.PluginCustomField.CustomFieldCollection.Plugin.Name == "Custom Field Demo")
                  {
                     //We have found the particular custom field we are interested in interrogating
                     if (existingCustomFieldValue != null && existingCustomFieldValue.Contents != null)
                        System.Windows.Forms.MessageBox.Show(string.Format("Line {0}, dispersal {1} - value of {2}: {3}",existingLine.ItemNo, existingDispersal.ItemNo, existingCustomFieldValue.CustomField.PluginCustomField.Name, existingCustomFieldValue.Contents));
                  }
               }
            }
         }
        }   


I've attached an updated plugin with the code above.
Attachments
Plugin Custom Field Demo.xml
(35.24 KiB) Downloaded 86 times
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 742
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 221

Re: Custom column values getting erased

Postby neil.interactit » Thu May 31, 2018 11:52 am

Sweet. Works a treat! Many thanks Scott.
neil.interactit
Kohai
Kohai
 
Posts: 227
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 20 guests

cron