passing optional parameters

Hi

Im creating a serach class based on five parameters from three different tables.I used a query to join tables and the query executing if i pass all the parameters.But for me the user can search on any combinations of parameters.For example he might search based on two parameters say name and age.How to achieve this.

Assign defualt values to the parameters…

Regards

Kranthi

Hi kranthi,

Thanks for your reply…

Actually i tried assigning default values but AX accepts optinal parameters from last(coorect if im wrong).But for me i want all the five parameters to be optional…

Kindly suggest.

I will be calling this method from .net using business connector. So i ll be declaring this method as static. So ill not be able to use the instances or fields declared in class declaration. So while passing the default parameter im getting an error varibale not been declared.

Kindly help…

Hi,

When you tried to create sales orders through .Net BC (I am referring to your earliest post), you were already calling static methods declared in Dynamics Ax.

In particular NumberSeq class → newGetNum method. There are 3 parameters however only one is mandatory. Code snippet below -


public static NumberSeq newGetNum(NumberSequenceReference _numberSequenceReference,
boolean _makeDecisionLater = false,
boolean _dontThrowOnMissingRefSetUp = false )


Hope this helps,

Hi Harish,

public static CustTable search(BirthDate DOB = dob ,
FirstName _firstName = firstname,
LastName _lastName = lastname)

If i include the above its stating an error variable dob not declared…

public static CustTable optinalsearch(BirthDate DOB = date dob ,
FirstName _firstName =str firstname,
LastName _lastName = str lastname)

then it is giving a syntax error…

Kindly suggest…

Hello,

The main difference between static and other method types is - in static method, it is not possible to use member variables. Therefore you cannot use variables like dob, firstname and lastname as you have done in your above example.

By default if you want to keep empty or null values, you should do like this -

…(BirthDate dob = datenull(),
FirstName firstName = ‘’,
LastName lastName = ‘’ )

Regards,

Hello,

The main difference between static and other method types is - in static method, it is not possible to use member variables. Therefore you cannot use variables like dob, firstname and lastname as you have done in your above example.

By default if you want to keep empty or null values, you should do like this -

…(BirthDate dob = datenull(),
FirstName fistName = ‘’,
LastName lastName = ‘’ )

Regards,

Thanks harish im able to pass optinal parameters in static methods now.

This is the search query im using for searching a customer based on any of these five criteria.The user can search on all paramters or any combination out of these five parameters.When im executing this query(with OR condition) im getting duplicate values and if im using a AND condition in this query empty record is returned.Suggest me a solution to resolve this.

public static CustTable searchall(BirthDate DOB = datenull() ,
FirstName _firstName=’’,
LastName _lastName=’’,
TypeId _identificationType=’’,
Details _details=’’)
{
CustTable _custTable;
CustIdentificationDetails _custIdentification;
DirPartyTable _partyTable;

;

select AccountNum, Name,Address from _custTable where
_custTable.BirthDate == DOB

join _partyTable

where
_partyTable.PartyId == _custTable.PartyId &&
_partytable.FirstName like _firstName ||

_partyTable.LastName like _lastName

join _custIdentification
where
_custIdentification.CustomerIdentificationTypeId like _identificationType &&
_custIdentification.IdentificationDetails like _details ||
_custTable.AccountNum == _custIdentification.CustomerId ;

return _custTable;

}