Showing posts with label Form. Show all posts
Showing posts with label Form. Show all posts

Thursday, June 8, 2023

Display path of navigation for a form.

 


Enable the legacy navigation bar in system administrator > setup > client performance options.





Keep Daxing!!

Monday, August 29, 2022

How to add fields to the form DirPartyQuickCreateForm in D365FO

 I got a requirement to add few fields while creating customer and those fields data should be auto populated from customer group.

  • To create customer/vendor the standard system will call the  DirPartyQuickCreateForm. 
  • We can't add fields directly to this form. It will not work and we can't get the control's in logic.

Solution :

  •     From form inti method the below will trigger.
        
  • Here They are calling field groups in table.
  • If you open the table you can find that groups.
            

  •  You can drag the required fields to the above mentioned groups.

  • For my requirement I have add the field in cust table and cust group and dragged in to that group.


  • For auto population I have added the below code in modified method

[ExtensionOf(tableStr(CustTable))]
final class custTable_Extension
{    
   public void modifiedField(FieldId _fieldId)   
   {        
	next modifiedField(_fieldId);

        switch(_fieldId)
        {
            case fieldNum(CustTable, CustGroup):
                this.MarkGUA = CustGroup::find(this.CustGroup).MarkGUA ;
                break;
        }
    }
 }



OuptPut :



Keep daxing!!

Monday, July 11, 2022

How to populate data in form with temp table data source using X++ In D365FO

 How to populate data in form with temp table data source using X++ In D365FO.

Here I am using RecordInsertList to insert data in Temp table.

  • I have added temp table in form.
  • In Form init method I am inserting data into temp table.
  • Using linkPhysicalTableInstance I have assigned to temp table buffer to data source.

Form Init method:

[Form]
Public void init()
{
    CustTable  custTable = element.args().record(); 

    MyTempTable.linkPhysicalTableInstance(MyTempTable::getTempTable(custTable)); // add tempTable instance
 
}
[Table method]

Public static MyTemptable getTempTable(CustTable  _custTable)

{
    MYTempTable         myTempTable;
    SalesTable          salesTable;
    RecordInsertList    tempRecordInsertList = new RecordInsertList(tableNum(MYTempTable),
                                                                     true, true, true, 
                                                                     false, true, myTempTable);
    while select salesTable
       where salesTable.CustAccount == _custTable.CustAccount 	
    {
        myTempTable.clear();
        myTempTable.CustAccount = salesTable.CustAccount;
        myTempTable.SalesId     = salesTable.SalesId;

        tempRecordInsertList.add(myTempTable);
    }

    tempRecordInsertList.insertDatabase();

    return myTempTable;
}

If you want to write select / while select statement for temp table follow the below logic. 
    MyTempTable    MyTempTableLoc; 
    MyTempTableLoc.linkPhysicalTableInstance(MyTempTable);// temp table buffer from init method.
    select MyTempTableLoc where 'your condition';
    while select myTempLoc
    {
        // your logic
    }
Keep Daxing!!

The parameter 'e' is not used in D365FO

 

In D365FO we get few BP warnings. 

  • If you use event handler most of the time we are getting "The parameter 'e' is not"  BP.  
  • (FormDataSourceEventArgs e) Most of the time we are not using this. We use this in lookup method.


To rectify this need to use below command.

SuppressBPWarning('BPParameterNotUsed', 'False positive') 

Below is the example for validate method.

[FormDataSourceEventHandler(formDataSourceStr(WHSLocation, WMSLocation),
                         FormDataSourceEventType::ValidatingWrite), 
SuppressBPWarning('BPParameterNotUsed', 'False positive')]
public static void WMSLocation_OnValidatingWrite(FormDataSource sender, FormDataSourceEventArgs e)
{

}


Keep Daxing!!

Wednesday, April 20, 2022

Add default filter in Systemdefinedfiterpane in D365FO

 Today we see to add default filter in Systemdefinedfiterpane.




For this we need to use QueryFilter class. Write the below method in form init method. I am using vend group table.


[ExtensionOf(formStr(VendGroup))] public final class TestVendGroupForm_Extension { public void init() { next init(); // QueryFilter qFilter; QueryBuildDataSource qbd = VendGroup_ds.queryBuildDataSource(); // qFilter = VendGroup_ds.query().addQueryFilter(qbd, fieldStr(VendGroup, PaymTermId)) VendGroup_ds.query().addQueryFilter(qbd, fieldStr(VendGroup, PaymTermId)); //VendGroup_ds.query().addQueryFilter(qbd, fieldStr(VendGroup, Name));         

        // ------Or---------------         this.addFilterPaneRanges(); }     /// <summary> /// Adds ranges to filter pane. /// </summary> protected void addFilterPaneRanges() { QueryBuildDataSource inventSumQbds = InventSum_DS.query().dataSourceName(InventSum_DS.name()); SysQuery::findOrCreateRange(inventSumQbds, fieldNum(InventSum, ItemId)); QueryBuildDataSource inventTableQbds = InventTable_DS_DS.query().dataSourceName(InventTable_DS_DS.name()); SysQuery::findOrCreateRange(inventTableQbds, fieldNum(InventTable, NameAlias));

    } }


Keep Daxing!!

Monday, February 14, 2022

Set Cursor on First field while creating the new Record in D365FO

Hi guys, Today we see how to set the cursor on the first field while creating the new record in D365FO using x++.

In my form, I have 2 data sources when I am trying to create a new record in form It automatically selects 1st form data source field. But as per my requirement, I have added the 2nd form data source field at first.
For achieving this we have 2 ways.

Way 1:
        Go to from data source field properties. we need to set skip property to yes. 
Path:
\Form\Myfrom\Data Sources\my datasouce\Fields\myfield
        


Way 2:
We can write in an active method from the data source.
first, we need set AutoDeclaration property is set to yes. (Selected field)

 public int active() {     int ret;     ret = super();     FormControlName.setFocus(); 

        return ret;

} 

Keep Daxing!!

Tuesday, December 28, 2021

Filter records in form in D365fo

Hi guys, Today we see how to filter the records in form using X++.

  • If it's a new form directly write the below code.
  •  If it's a standard form. create extension class.
Here we have 2 ways. Follow anyone.

Way 1:

    public QueryBuildRange qbr;//declare this variable globally. public void init()// dataSource init method { super(); qbr = this.query().dataSourceTable(tableNum(InventSite)).addRange(
                                                        fieldNum(InventSite, IsActive)); } public void executeQuery()// dataSource { FormRun formRun = element; if (formRun.args().menuItemName() == menuItemDisplayStr(InventSite)) { qbr.value(queryValue(NoYes::Yes)); } next executeQuery(); 

} 


Way 2:

    public void executeQuery()// dataSource { FormRun formRun = element; if (formRun.args().menuItemName() == menuItemDisplayStr(InventSite)) { this.initializeQueryFromType(); } next executeQuery(); } public void initializeQueryFromType() { QueryBuildDataSource qbDataSource; ; qbDataSource = this.query().dataSourceTable(tableNum(InventSite)); qbDataSource.clearDynalinks(); qbDataSource.addRange(fieldNum(InventSite,                                              isActive)).value(SysQuery::value(NoYes::Yes));

}

Keep Daxing!!

Tuesday, November 16, 2021

Add symbol icons to the Grid in Dynamics 365FO

 

    We see how to add symbol icons to the grid in Dynamics 365FO. I have to add icons to the records based on qty. 


For this, 

1. I have created a display method on my table.     

    [SysClientCacheDataMethod(true)]
    public display container logo()
    {
        ImageReference          imageReference;
        container               image;
        
        
        //imageReference = ImageReference::constructForSymbol(
				this.QtyAvailable mod 2 ? 'GreenCheck' : 'RedX');
				
        str name = this.QtyAvailable mod 2 ? 'GreenCheck' : (
				this.QtyAvailable mod 3 ? 'YellowTriangle': 'RedX');
        imageReference = ImageReference::constructForSymbol(name);

        if (imageReference)
        {
            image = imageReference.pack();
        }

        return image;
    }

2. Created new Form image control in the form grid and set up the properties for that control.





Symbols:
  • GreenCheck
  • YellowTriangle
  • RedX
  • GreenCircle
  • RedDiamond
  • BlueSquare
  • RedSquare
  • GreenSquare
  • OrangeSquare
  • GreenSquare
  • YellowSquare
  • TemporaryUser
  • EditEvent
  • YellowExclamationPoint
We can use the above symbols as per our requirements.

Reference: https://www.avantiico.com/adding-symbol-font-icons-to-a-grid-in-dynamics-365-for-finance-and-operations-enterprise-edition/

Keep Daxing!!

Monday, November 15, 2021

Add custom dialog form to standard new button in form in d365fo using x++

 Hi guys, I got a requirement like I have to add my custom dialog to the standard New button. I have to change the standard new button operation and I have to add a custom one. Please refer below for the solution.




My custom form


Way 1:

  • In the form design 'Show new button' property I have set it as no. I add a new menu item button in the form and I have called my custom form in that button properties.


Way 2:

  • Override the Create method in the form data source and write the below logic. (Main form). From here we can call our custom form by using args class. Here we have to comment super() otherwise the standard code will run. 
        public void create(boolean _append = false)
        {
            //super(_append); we need to comment super.

            Args            args = new Args();

            args.name(formStr(MyForm));
            args.caller(this);
            args.record(MyTable);

            FormRun myCreateOrder = classfactory.formRunClass(args);

            myCreateOrder.init();
            myCreateOrder.run();

            if  (!myCreateOrder.closed())
            {
                myCreateOrder.wait();
            }

            if  (myCreateOrder.closedOk())
            {
                Info('Clicked ok');
                //MyTable_ds.research(true);
            }
            else
            {
                Info('Clicked cancle');
            }
        }


  • Write the below code in the clicked method of custom form OKCommandButton.

                Mytable      mytable;

        ;

        super();

        if  (MyID.valueStr())
        {
            ttsbegin;
            mytable.clear();
            mytable.MyID = MyID.valueStr();
            mytable.Qty = 1;
            mytable.String = 'Test';
            mytable.InventLocationId = '11';
            mytable.insert();
            ttscommit;

            element.args().record().dataSource().research(true);
        }

  • When I click the new button my custom dialog will open. After entering the my Id and I clicked on the ok button it will insert data in my table and refresh the caller form. 
Keep Daxing!!

Add an image to a button in d365fo.


Today we see how to add image to custom button in d365fo. I got a requirement like I have to add standard button images to my custom buttons.

For this I have set up one property. Just check below.

Image location as symbol.

Normal Image as new(required symbol name).


Result.


Refer below link for button image names.

https://docs.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/user-interface/action-controls#button-images


Keep Daxing!!


Wednesday, February 3, 2021

Based on security roles to enable or disable the Fields in a form in D365FO

 Hi guys, Today we see how to Based on security roles to enable or disable the Fields in a form in D365 FO.

Please check below code.

    [FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesTable), FormDataSourceEventType::Activated)]

    public static void SalesTable_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)

    {

        securityrole            role;

        securityuserrole        userrole;

        boolean                 check;

        

        select firstonly RecId from role

                    join userrole

                where role.recid == userrole.securityrole

                && role.name== 'Test'

                && userrole.user == curuserid();


        check = (role.recid ? true : false);


        sender.object(fieldNum(SalesTable, TestField)).allowEdit(check);

}


Keep Daxing!!

Tuesday, September 29, 2020

Get selected records from grid in AX2012 using X++

 Hi guys, Today we see how to get selected records from the grid in Ax 2012 using X++.

write below code in the clicked method.





void clicked()

{

    CustomerTable  customerTableLoc;


    CustomerTable_DS.Anymarked();// check user selected the record or not.

    for (customerTableLoc= getFirstSelection(CustomerTable_DS);customerTableLoc;customerTableLoc=CustomerTable_DS.getNext())

    {

    if (customerTableLoc.recid)

    {

        info(customerTableLoc.CustAccount);

    }

  }

}

-------------------------------------------Or-------------------------------------------------

CustomerTable  customerTableLoc;

MultiSelectionHelper helper = MultiSelectionHelper::construct();


helper.parmDatasource(CustomerTable_DS);


customerTableLoc = helper.getFirst();


while (customerTableLoc.RecId)

{

    info(customerTableLoc.CustAccount);

    customerTableLoc = helper.getNext();

}


Result:


Keep Daxing!!

Sunday, September 27, 2020

Enable or Disable the Unbonded Fields on Form in ax 2012 using X++

 

Hi guys ,Today we see how to enable Unbonded fields on form in ax 2012 using X++.

Here i write code in active method. Just check below example.


if(Table.Name== "Test")

{

    Table_ds.object(fieldNum(Table, Field)).enabled(true);

}  

------------Or-----------

Table_ds.object(fieldNum(Table, Field)).enabled(Table.Name== "Test");


Examples:

public int active()

{

int ret;

ret = super();

Table_ds.object(fieldNum(Table, Field)).enabled(Table.Name== "Test");

return ret;

}

Below example for Vendor Bank account number and name.


public int active()

{

    int ret;

    ret = super();

    VendBankAccount_ds.object(fieldNum(VendBankAccount, AccountNum)).enabled(VendBankAccount.WorkflowStatus==WorkflowStatus::Approved || VendBankAccount.WorkflowStatus==WorkflowStatus::NotSubmitted);

    VendBankAccount_ds.object(fieldNum(VendBankAccount, Name)).enabled(VendBankAccount.WorkflowStatus==WorkflowStatus::Approved || VendBankAccount.WorkflowStatus==WorkflowStatus::NotSubmitted);

    return ret;

}

Keep Daxing!!


Wednesday, September 2, 2020

Filtering Records in a Form in AX 2012 using X++

 Hi guys,Today we see Filtering records in a Form in AX 2012 using X++.


Based on My Combo Box selection I have to filter the record in grid

On Form ClassDeclaration:

public class FormRun extends ObjectRun

{

        QueryBuildRange qr;

}


Apply the Range on Form DataSource Init():


public void init()

{

    super();

   qr=this.query().dataSourceName('InventSum').addRange(fieldNum(InventSum,Itemid));

}

On Form DataSource executeQuery():

   public void executeQuery()

{

      qr.value(Gender.valueStr());

      super();

}


IF its Enum Type Write Code on Selection change Method.

On ComboBox SelectionChange() Method Call Data Source Execute Query():

public int selectionChange()

{

    int ret;

    ret = super();

    InventSum_ds.executeQuery();

    return ret;

}


IF its String or int Type Write Code on modified Method.


public void modified()

{

    int ret;

    ret = super();

    InventSum_ds.executeQuery();

    return ret;

}


Keep Daxing!!

Thursday, August 13, 2020

Restrict the user to Open Form, if Already Opened by others Ax 2012

Hi frnds, Today we see how to restrict the user to open form , if That form is already open by other users in AX 2012.

Here I take 2 customized Forms With customized Table.In customized table UserId field is added.

And based that user id I am Implement the code.

In child form i added Init method And Close method.


Init Method:

public void init()

{

    DaxTestIn daxTestIn;

    Formrun formrun;

        super();

    daxTestIn = element.args().record();

    formrun = element.args().caller();

        if (!daxTestIn.User)

    {

        ttsBegin;

        daxTestIn.User = curUserId();

        daxTestIn.doUpdate();

        ttsCommit;

    }

    else if(daxTestIn.User != curUserId())

    {

        throw error(strFmt("The same AccountNum(%1) is already opened by %2", daxTestIn.AccountNum,daxTestIn.user));

    }

}


Close Method:


public void close()

{

    DaxTestIn daxTestIn,daxTestInLoc;

    Formrun formrun;

       super();

    daxTestIn = element.args().record();

    formrun = element.args().caller();

    if (daxTestIn.User)

    {

        ttsBegin;

        select forUpdate daxTestInLoc where daxTestInLoc.RecId==daxTestIn.RecId;

        daxTestInLoc.User = ' ';

        daxTestInLoc.doUpdate();

        ttsCommit;

    }

}


Output:




If i try open 1001 record It throw that error.

That 1001 record is is already used by other user.



Keep Daxing !!



I saw other Blog  they consider SessionId and they worked on sales order.Check below link for that blog.

https://ax1231.wordpress.com/2018/02/06/restrict-the-user-to-open-the-particular-form-if-the-same-form-already-opened-by-any-other-user/