Page 1 of 1

SetControlPermissions

PostPosted: Wed Mar 09, 2016 4:53 pm
by neil.interactit
Hi guys,

I am getting a strange error that I can't nail ...

Error: Object reference not set to an intance of an object. Module : SetControlPermissions

This occurs in a plugin on the CreditorPurchases form. I have (manually) added and populated some extra grid columns.

Initially I was getting this error when opening the form. I managed to solve this by now adding the columns to the grid in the _creditorPurchases.Load event handler, which all works perfectly.

All functionality works fine on and after opening the form, until I navigate to another batch record ... then I get Error: Object reference not set to an intance of an object. Module : SetControlPermissions, which seems to also kill any further plugin code from running.

The code that adds the column is akin to the following:

Code: Select all
        _creditorPurchases = (CreditorPurchases)JiwaForm;
        _sheet = _creditorPurchases.grdLines.ActiveSheet;
        [SNIP]
        var col = _sheet.ColumnCount;
        _colFilename = col;
        _sheet.ColumnCount += 1;

        _sheet.ColumnHeader.Cells[1, _colFilename].Text = "Attachment";
        _sheet.Columns[_colFilename].Width = 300;
        _sheet.Columns[_colFilename].CellType = new TextCellType() { NullDisplay = "Drop file(s) here, or select", ReadOnly = true };

Wrapping this in a Try-Catch doesn't help, and in fact after adding debug logging to EVERY method in the plugin I discovered that none of them fire, on record change, prior to the error displaying (or at all).

My guess is that I need to register something so that SetControlPermissions knows about the new column?

Cheers,
Neil.

Re: SetControlPermissions

PostPosted: Thu Mar 10, 2016 8:31 pm
by Mike.Sheen
neil.interactit wrote:My guess is that I need to register something so that SetControlPermissions knows about the new column?


You shouldn't need to - unless you have set permissions for the new column - in that case it may be the base form class is trying to apply a permission to a column which doesn't exist until your plugin has a chance to add it.

You can help us out to troubleshoot this by providing a plugin which replicates the issue. We'll then be able to advise if it is an issue with the permissions system, and if we can provide a work-around for it.

Re: SetControlPermissions

PostPosted: Fri Mar 11, 2016 8:18 am
by neil.interactit
Hi Mike,

Thanks for taking a look at this. Minimal sample attached. You sgould see the error when you open Creditors / Transactions / Purchases / Purchases.

Cheers,
Neil.

Re: SetControlPermissions  Topic is solved

PostPosted: Sat Mar 12, 2016 2:24 pm
by Mike.Sheen
The problem is when the base class tries to apply permissions, it assumes each column has a tag which is a unique text identifier for the column - and your columns were added without setting the key.

The easiest way to resolve this is to use the AddColumn method of the grid.

Code: Select all
_creditorPurchases.grdLines.AddColumn("Attachment", new TextCellType(), "Attachment", 8, false, true, false, true);
_creditorPurchases.grdLines.AddColumn("Upload", new JiwaLookupButtonCellType(), "Upload", 8, false, true, false, true);
_creditorPurchases.grdLines.AddColumn("Uploading", new ProgressCellType() { ShowText = false, }, "Uploading", 8, false, true, false, true);


Attached is your plugin modified to use the above.

Re: SetControlPermissions

PostPosted: Tue Mar 15, 2016 8:46 am
by neil.interactit
Hi Mike,

Very sweet! Many thanks.

Cheers,
Neil.