Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Opening Form Programmatically with datasource not attached to call

1,091 views
Skip to first unread message

David Bowles

unread,
Jul 15, 2009, 8:57:01 AM7/15/09
to
Hello All,

I cannot seem to figure out the simple mistake I'm committing with the
following code and wonder if someone out there can help me as I believe my
frustration is clouding my judgement.

I am trying to open the DocuView window and pass across a datasource of the
LedgerJournalTrans Table to display documents linked to those records. The
problem is I want to do this from the LedgerTransAccount form which has the
LedgerTrans table as it's datasource.

To reconcile the difference, I am performing a select statement against
LedgerJournalTrans where LedgerJournalTrans.Voucher = LedgerTrans.Voucher.

This in essence, gives me the LedgerJournalTrans record that I need to pass
over to DocuView to get the linked document.

I have added a button of MenuItemButton type, with a MenuItemName property
of 'DocuView'. I have also attached a clicked() method to the button that
executes the following code:

void clicked()
{

FormRun a_FormRun;
Args a_Args;
LedgerJournalTrans ljt;

;

SELECT FIRSTONLY ljt
WHERE ljt.Voucher == LedgerTrans.Voucher
&& ljt.AccountType == LedgerJournalACType::Vend;


if(ljt)
{
a_Args = new Args(ljt);
a_Args.name(formstr(DocuView));
a_FormRun = ClassFactory.formRunClass(a_Args);
a_FormRun.init();
a_FormRun.run();
a_FormRun.wait();
}
super();
}

When this code is executed through a button click, all I get is an error
that states "Object 'Args' could not be created."

I had this working, however our code deployer accidentally overwrote this
changes and I lost the functionality. I went back to a process I created
where I capture and write out all new changes to the AOT, but for some reason
now it does not work.

I know this is not the best practice way to open a form, however the unique
situation here is the datasource of the calling form is not the datasource I
want to pass across to be the basis for the new form.

Any ideas on may obviously simple problem would greatly be appreciated.

--
David Bowles
Developer/MCP

Klaas Deforche

unread,
Jul 15, 2009, 10:15:02 AM7/15/09
to
Hi David,

Shouldn't it be:
a_Args = new Args();
a_args.record(ljt);

in stead of
a_Args = new Args(ljt);

Kind regards,
Klaas
------------------
http://www.artofcreation.be

Axel Kühn

unread,
Jul 15, 2009, 10:24:01 AM7/15/09
to
Hi David,

please try this.

a_Args = new Args();
a_Args.record(ljt);


a_Args.name(formstr(DocuView));
a_FormRun = ClassFactory.formRunClass(a_Args);
a_FormRun.init();
a_FormRun.run();
a_FormRun.wait();

Hope this hepls you.
--
Sincerely yours
Axel Kühn (visit my Dynamics AX blog at: http://blog.ak-home.net)

Axel Kühn

unread,
Jul 15, 2009, 10:29:03 AM7/15/09
to
In addition:

Insted of using formrun to open the docuView form
you can also call

DocuRef::openDocHandling(<record>, <callerform>)

--
Sincerely yours
Axel Kühn (visit my Dynamics AX blog at: http://blog.ak-home.net)

David Bowles

unread,
Jul 15, 2009, 10:58:25 AM7/15/09
to
I have tried this also, the problem with doing the call this way, I don't get
an error, and I do get the DocuView form, however in the title bar of the
form I get "Document Handling of Unlinked - Journal Number...." However, the
same Journal Number and Voucher number it displays is the same journal number
and voucher that displays if I use the document handling icon from the
AP/Invoice Journal/Lines form.

I also tried your second suggestion and I don't have a static class method
called openDocHandling on my DocuRef class. I am on AX 4.0 RTM. We haven't
upgraded to 2009, yet.

I'll keep playing with it. I know it's something very simple I am missing
but I haven't ran across the problem, yet.

Thanks again,
--
David Bowles
Developer/MCP

Axel Kühn

unread,
Jul 16, 2009, 5:23:00 AM7/16/09
to
Hi David,

i looked into this once again.
You are right. Calling to DocuView form with or over args and formrun
doesn't work.

But there is another (even simplier) way to open the docuview form for an
spezified record.

1. Add the MenuItem (Display) "DocuView" as MenuItemButton to your form.
No need to set the properties "DataSource" and so on for the MenuItemButton.
Yust place the MenuItem on your form.

2. Write a new Method "docCursor" on your Form which returns the record of a
datasource for which the docuview should be opened.

Example:
common docCursor()
{
;
//Must be a datasource on the form, doesn't work with a table buffer.
return custTable;
}

For you this means:

1. Add the LedgerJournalTrans as a Datasource to your Form.
2. Write a new method "docCursor" on your form which return the
LedgerJournalTrans record.
3. Place the MenuItem "DocuView" on your Form.

I have tested this in AX 4.0 and AX 2009. Works great.

Hope this helps you.

0 new messages