Page 1 of 2

Debtor Import - importing Custom Settings

PostPosted: Thu Jan 19, 2023 10:19 am
by neil.interactit
Hey guys,

I have a requirement to populate some custom settings when importing records via Debtor Import.

I haven't been able to nail this. Adapting from viewtopic.php?f=26&t=1674 I wasn't able to get DestinationProperties.ReadEnd to even fire, and at the Imported event, I could not spot where in the DebtorImport object to access and process additional data.

Would you be able to provide a small sample plugin to get me started?

Cheers,
Neil.

Re: Debtor Import - importing Custom Settings

PostPosted: Thu Jan 19, 2023 12:29 pm
by Mike.Sheen
neil.interactit wrote:Hey guys,

I have a requirement to populate some custom settings when importing records via Debtor Import.

I haven't been able to nail this. Adapting from viewtopic.php?f=26&t=1674 I wasn't able to get DestinationProperties.ReadEnd to even fire, and at the Imported event, I could not spot where in the DebtorImport object to access and process additional data.

Would you be able to provide a small sample plugin to get me started?

Cheers,
Neil.


Custom fields are supported out of the box for debtor imports.

You'll see the custom fields at the bottom of the drop-down combo when mapping source to the destination column.

DebtorImportCustomFields.png


We'll auto-map if we find a column in the CSV with a header matching the custom field name.

Re: Debtor Import - importing Custom Settings

PostPosted: Thu Jan 19, 2023 1:41 pm
by neil.interactit
Thanks Mike.

My bad for not being specific ... there is some custom logic also required (if no value supplied, auto generate and assign a new value). So I was hoping to intercept via a plugin to be able to achieve this.

Cheers,
Neil

Re: Debtor Import - importing Custom Settings

PostPosted: Thu Jan 19, 2023 3:30 pm
by SBarnes
Try reading this post where Mike suggested how to do it for inventory, it should work the same.

Re: Debtor Import - importing Custom Settings

PostPosted: Thu Jan 19, 2023 3:57 pm
by neil.interactit
Thanks Stuart, yes I tried that, but no joy ... I wasn't able to get DestinationProperties.ReadEnd to fire in the debtor import scenario.

Re: Debtor Import - importing Custom Settings  Topic is solved

PostPosted: Thu Jan 19, 2023 4:15 pm
by SBarnes
What service release are you on this could be your problem if you are not on SR5 or greater.

Post the plugin that you have might help as this might also

Re: Debtor Import - importing Custom Settings

PostPosted: Fri Jan 20, 2023 2:15 pm
by neil.interactit
Thanks Stuart.

That helped. I adapted your (final) sample to provide the functionality needed.

Mike, fyi, using Stuart's final sample in SR13 here, the BusinessLogicPlugin section appears not to fire (no "would have been set by this" MessageBox from there).

In case it helps others, here is the code to allow a Custom Field Value to be set algorithmically during the Debtor Import process ...

Code: Select all
using JiwaFinancials.Jiwa.JiwaDebtors;
using JiwaFinancials.Jiwa.JiwaDebtors.Import;
using JiwaFinancials.Jiwa.JiwaDebtorsUI.Import;

namespace DebtorImportBPayCRN
{
    #region "FormPlugin"
    public class FormPlugin : System.MarshalByRefObject, JiwaFinancials.Jiwa.JiwaApplication.IJiwaFormPlugin
    {
        public override object InitializeLifetimeService()
        {
            // returning null here will prevent the lease manager
            // from deleting the Object.
            return null;
        }
        public void SetupBeforeHandlers(JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm JiwaForm, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
        {
            var form = JiwaForm as MainForm;
            if (form == null) return;
            Helper.Manager = JiwaForm.Manager;
            form.BrowseUltraButton.Click += delegate { SetBpayCrn(form.DebtorImportObject.DestinationProperties); };
        }
        public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm JiwaForm, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
        {
        }
        public void SetBpayCrn(DestinationPropertyCollection destinationPropertyCollection)
        {
            destinationPropertyCollection["Debtor.AccountNo"].SetterMethod = delegate (Debtor debtor, string value, string rowData, string[] row, int rowNo, Mapping mapping)
            {
                debtor.AccountNo = value;
                var bpayCrn = debtor.CustomFieldValues.get_ItemFromSettingName("BpayCrn");
                if (string.IsNullOrEmpty(bpayCrn.Contents)) bpayCrn.Contents = NextBpayCrn();
            };
        }
    }
    #endregion
}


Cheers,
Neil

Re: Debtor Import - importing Custom Settings

PostPosted: Fri Jan 20, 2023 2:40 pm
by Mike.Sheen
neil.interactit wrote:Mike, fyi, using Stuart's final sample in SR13 here, the BusinessLogicPlugin section appears not to fire (no "would have been set by this" MessageBox from there).


That sounds like a problem with Stuarts plugin - you should engage the author to address that :)

I'm not sure if you're reporting an issue now or not... If the code you have shown works, then that indicates that the import works as intended.

Re: Debtor Import - importing Custom Settings

PostPosted: Fri Jan 20, 2023 2:45 pm
by SBarnes
That sounds like a problem with Stuarts plugin - you should engage the author to address that :)



hqdefault.jpg
hqdefault.jpg (20.16 KiB) Viewed 5771 times

Re: Debtor Import - importing Custom Settings

PostPosted: Fri Jan 20, 2023 2:47 pm
by Mike.Sheen
NO GOOD DEED GOES UNPUNISHED