Is there a way to display an info log when selecting a certain record in a dropdown menu/based on a field value?
For example:
When creating a new Quotation, if I select a customer which is bankrupt (so the value on the field bankrupt is true for that customer.) I want to show a info dialog: "Bankrupt!" I want to show this before the record is being created, at the moment it is being selected.
In your form find the field you want (form layout, no datasource), override Modified method an put your code before super();
To get the value use: this.text(); Here you can get the select value before insert.
Code example:
public boolean modified()
{
boolean ret;
CustTable custTable = CustTable::find(this.text());
if (custTable.Bankrupt == NoYes::Yes)
info("Bankrupt!");
ret = super();
return ret;
}
Related
I want to initialize a value of an edit method inside the init method of form, i wrote this:
[Form]
public class foo extends FormRun
{
str paymTermId;
public void init()
{
CustTable custTable = CustTable::find("DE-001");
paymTermId = custTable.paymTermId;
super();
}
edit str edtpaymTermId(boolean set, str _paymTermId)
{
if (set)
{
paymTermId= _paymTermId;
}
return paymTermId ;
}
}
But when i open the form the control remains empty.
any suggestions?
I tried to reproduce the issue, but was not successful. For me, when opening the form, the control shows a value.
A possible reason why it is not working for you could be that you open the form in the wrong company. In your code, you retrieve the value to display in the control from the payment term of customer DE-001. This customer exists in company USMF in the Contoso demo data and has payment term Net10. If the form is opened in this company, the value is shown in the control. If you are in another company (e.g. DAT), no value is shown.
I see 2 things that are wrong:
You are setting the value BEFORE super(). It should be after.
You SHOULDN'T initialize the value via field, you should do it calling edit method. Edit methods have a boolean SET parameter which can simulate a call for setting a value.
I have a form with 2 fields, the 1st is filled with a lookup and the 2nd (not editable, just a Description of the 1st) is filled with a "display" method in the form.
public display Name displaySalesChannelName()
{
return SalesChannelTable::find(SalesChannelFilter.valueStr()).Description;
}
Seems to work fine, but only shows the value when the field is clicked.
How can I synchronize this 2 fields?
You can override method modified of the 1st control (with the lookup) and call method update of the 2nd control from there, e.g. if the name of the 2nd control is SalesChannelName and its AutoDeclaration property has been set to Yes, then:
public boolean modified()
{
boolean ret = super();
SalesChannelName.update();
return ret;
}
But then there's not much sense in using a display method here. You can just as well clear the DataMethod property of the 2nd control, and the modified method above can be rewritten as follows:
public boolean modified()
{
boolean ret = super();
SalesChannelName.text(SalesChannelTable::find(this.valueStr()).Description);
return ret;
}
you should try to put the display method on table level, your field's properties in the form must have the datasource Table name as datasource and your method's name as data method
I have modified a validate method of form control. On this control I'm typing the product name.
In validate method I'm checking if this product name exists in the table. If it does not exists the error is thrown.
My issue is that after the error is thrown I want to clear control. Here is my code:
public boolean validate()
{
InventTable inventTable;
boolean ret = super();
select inventTable
where inventTable.nameAlias == this.text();
if (!inventTable.recid)
{
error("error");
this.text("");
}
return ret;
}
this.text(""); does not work. So how can I clear the control? The control is a field from my datasource.
In validate methods you do not need to clear the field. The system does that for you when validate returns false.
So instead of this.text('')) just return false.
But I doubt that the idea of users entering the full name is really useful at all.
If you use NameAlias as an alternate item number an even easier option exist.
Change the AliasFor property on the InventTable.NameAlias field to point to ItemId.
When entering in an ItemId and you enter a NameAlias instead, it is translated to the corresponding item id by the AX run-time. This happens everywhere an item id is entered and validated.
When we create a dialog, how do we get the selection criteria for the record (Select button) and how do we disable the select button on the Dialog ?
I will assume you use the RunBase framework.
For the dialog part of your question see Axapta Dialog Validation.
To show the query dialog, you must provide two methods:
public boolean showQueryValues()
{
return true;
}
and
public QueryRun queryRun()
{
return queryRun;
}
The queryRun method must return a valid non-null value.
The queryRun instance variable is usually assigned a value in the unpack and initParmDefault methods.
Take a look on the CustInterestCancel class for a concise example.
How to disable the select button: return false from showQueryValues.
I have created a grid view of Leavemaster table and leaveApplication table.
There is field LeaveId in LeaveMaster and foreign key in LeaveApplication table.
I want to, when I select leaveId in LeaveAppliation table, automatically have related fields like LeaveName be filled according to LeaveId.
If you only want to show the leaveName use a display method defined on the LeaveApplicationTable:
display EmplName leaveName()
{
return LeaveMasterTable::find(this.LeaveId).Name;
}
If you have more fields to show consider using outer-join.
In the LeaveApplicationTable form add the LeaveMasterTable as a secondary datasource and use outer-join as the joinMode (Allow-Edit: false).
Add a modified method to the LeaveId field on theLeaveApplicationTable datasource:
public void modified()
{
super();
leaveMasterTable.data(LeaveMasterTable::find(leaveApplicationTable.LeaveId));
leaveMasterTable_ds.refresh()
}
Also change the validateWrite and write methods of the LeaveMasterTable datasource to not change any data:
public boolean validateWrite()
{
return true;
}
public void write()
{
//super();
}