Oly G.
Oly G.

Reputation: 27

How to add/save temporary table on form

We created special form to creating purchase prices for vendors.

New form has almost the same fields as original (so we used PriceDiscTable), but the record/datasoruce was set as temporary table. After user filled mandatory fields will click button, (extra logic behind) and record will inster to database (real priceDiscTable).

The idea was to grand access to trade prices for users that not necessarily has access to purchase prices. In theory everything was ok, but when user with no access to PriceDiscTable open new form, error was shown "Not enougt right to use table 'Price agreements'".

We try set the AllowCheck to false in formDatasource but this only allow us to open the form, but user still cannot add or modify records.

Is there any way to force system to allow user to write data in the temporary table?
Disabling security key or grand access to real table is not an option.
Duplicate table and create with same fields is nuisance (if we use same table we can use data() method to assign fields)

Upvotes: 1

Views: 3781

Answers (3)

Alex Kwitny
Alex Kwitny

Reputation: 11564

You will not be able to display the PriceDiscTable without giving the user at least "view" access or editing Classes\FormRun to somehow bypass the security key, which is kernel level so it's also not possible.

I agree with 10p where you should create a temp table and then create a custom method handler combined with buf2bufbyname() or buf2buf().

Another option you can screw around with, if you REALLY want to use .data() is using a Common as the datasource. You could add the fields you want on the grid with the common, then you can pass a common back/forth. This has a good amount of form setup to get this working, but it could produce what you want eventually I think.

static void Job8(Args _args)
{
    Common common;
    salesTable salesTable;
    ;

    common = new DictTable(366).makeRecord();

    select firstonly common where common.RecId == 5637145357;

    salesTable.data(common);

    info(strfmt("%1 - %2", salesTable.SalesId, salesTable.SalesName));
}

Upvotes: 0

10p
10p

Reputation: 6793

I think that creating a new temporary table with [almost] the same fields would be the best solution.

If the only reason you oppose to this approach is that you wouldn't be able to use data() to copy data from one table to another you can use buf2BufByName() as described here: http://mybhat.blogspot.co.uk/2012/07/dynamics-ax-buf2buf-and-buf2bufbyname.html

Upvotes: 2

Alex Kwitny
Alex Kwitny

Reputation: 11564

You can use RunAs to impersonate another user...perhaps a system user. I don't entirely follow what you are trying to do, but it sounds like this solution would work for you if you know exactly what your custom code is doing and is capable of.

See Classes\AifOutboundProcessingService\runAsWrapper to see an example.

Upvotes: 0

Related Questions