Symbol was not found when using tmpaccountsum variable in form - axapta

In the ReqTransPO form I want to use the tmpAccountSum table to store some values in which I later need to filter my grid.
In the classdeclaration I declared:
tmpAccountSum mytable;
In a helper method I have:
//Store data in tmptable
ttsbegin;
mytable.AccountNum = _reqTrans.RefId;
mytable.Txt = _reqPo.RefId;
mytable.Voucher = enum2str(_prodstatus);
mytable.insert();
ttscommit;
I don't get an error on 'mytable' but can't really use it / it's not initialized. If I add a watch in debug I see:
Error: Symbol "mytable" was not found
If I declare mytable locally it works ok.
Guess I'm doing something wrong?
Thanks in advance,
Mike

My extrasensory perception tells me, that your helper method is static.
Static methods do not have access to instance variables declared in classDeclaration.

Related

initializing variable with select in init method using x++

I'm new with X++ and I'm trying to modify the INIT method of a form in order to greet the user wit a message on top of the form.
The greeting message should look like "Happy Birthday EmplTable.name!".
The code from the INIT METHOD looks like this till now:
public void init()
{
CustName custName = SELECT EmplTable.name FROM Empltabe JOIN UserLogInfo WHERE EmplTable.EmplId == UserInfo.UserId;
;
//"#NET4183"
super();
GreetingMessage.text(strfmt("#NET4183", custName));
}
I have a hard time understanding what is wrong here and why I can't initialize the custName variable.
Thank for the help!
Have a great day!
All variables must be declared before they can be used. X++ does not allow variable declarations to be mixed with other X++ statements; variables must be declared before X++ statements.
Declaration of Variables
You should declare variables EmplTable, UserInfo before you can use them in select statement.
Results of a select statement are returned in a table buffer variable. If you use a field list in the select statement, only those fields are available in the table variable.
You can assign value to your custName variable using this peace of code
custName = emplTable.name;
This link will give you a hint how to find the current user
curUserId Function

Magic Casting to collection of results

In the Simple.Data examples, there is an example of 'Magic Casting':
// When you assign the dynamic record to a static type, any matching properties are auto-mapped.
var db = Database.Open();
Customer customer = db.Customers.FindByCustomerId(1);
Does Simple.Data also magically cast if there are multiple records returned? Something like this:
var db = Database.Open();
IEnumerable<Customer> customers = db.Customers.FindBySurname("Smith");
Obviously I have tried the above and it doesn't work ("Cannot implicitly convert type" from SimpleQuery to my concrete type). Any advice would be welcome.
FindBySurname returns a single record. If you use FindAllBySurname you'll get an enumerable, which should magic cast OK. (If for some reason it doesn't, you can call .Cast() on it.)

flex data provider not working if XML has single node value or less

i get this error when i retrieve an XML that only has 1 node (no repeating nodes) and i try to store in an ArrayCollection. -When I have MORE than 1 "name" nodes...i do NOT get an error. My test show that XMLListCollection does NOT work either.
TypeError: Error #1034: Type Coercion failed: cannot convert "XXXXXX" to mx.collections.ArrayCollection.
this error occurs as the line of code:
myList= e.result.list.name;
Why can't ArrayCollection work with a single node? I'm using this ArrayCollection as a dataprovider for a Component -is there an alternative I can use that will take BOTH single and repeating nodes as well as work as a dataprovider? Thanks in advance!
code:
[Bindable]
private var myList:ArrayCollection= new ArrayCollection();
private function getList(e:Event):void{
var getStudyLoungesService:HTTPService = new HTTPService();
getStuffService.url = "website.com/asdf.php";
getStuffService.addEventListener(ResultEvent.RESULT, onGetList);
getStuffService.send();
}
private function onGetList(e:ResultEvent):void{
myList= e.result.list.name;
}
the problem here is, that if you only have one row Flex will complain since it cannot use the result as arrayCollection.
My work around was, that you put number of rows into your XML with the data you want to return:
for example I did:
<list><nr_rows>3</nr_rows><name>...</name><name>...</name><name>...</name></list>
So when I get the result back I do a check of how many rows I am getting with (You can get the number of rows returned from MySQL query with mysql_num_rows)
e.result.list.nr_rows
So if this is one, you add Object to the arrayCollection, if there are more than one you can just use result and equal it to AC (in this case projects is AC):
if (event.result.list.nr_rows == '1'){
myList.addItem(event.result.list.name);
} else {
myList = event.result.list.name;
}
If you are not particular about getting the final result onto a ArrayCollection, you can do the following to get the final result onto an XMLList or XMLListCollection.
1) set the resultFormat property of HTTPService to e4x.
2) Do not mention the root xml tag name while referencing it. Reference the output as: myList:XMLList = e.result.name.
This works whether the retrieved XML has one or more than one elements.
I just had this problem today and it led me to this question. I'm not sure if your use-case is exactly the same as mine, but you might want to try showRoot="true" on the mx:Tree. It seems to force the root node to be shown when there is only one item, and gets ignored with multiple items.
add a row object to get the row of the XML node can work, but I think some better method have be, is ActionScript is as powerful as Java?

Birt Global Integer

I have a Birt Report which read some stuff from a database.
After that i want to increment a global Integer for every Detailrow that is loaded.
So far i have initialized a global Integer with the following lines:
importPackage(Packages.java.lang);
reportContext.setPersistentGlobalVariable("minTotalPlus", new Integer(0));
After that i added the following line into a field in my detail row:
reportContext.setGlobalVariable("minTotalPlus", new Integer reportContext.getGlobalVariable("minTotalPlus")) + 1);
When i preview the report i get an "java.lang.NumberFormatException: null" which means that the global variable is null. Why is that so? How could I fix that?
Dont' declare variables like that in the initialize method
declare the like the following
materiales=0;
tools=0;
then in the fetch method
use the following
tools++;
...etc.

Populate ParameterCollection w/ sp_columns (or INFORMATION_SCHEMA.Columns) Results

I'd like to build a ParameterCollection object based on the results of either execute sp_columns MyTableName or SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = 'MyTableName'.
The problem I'm having is assigning the appropriate data type to each Parameter ... I'm unsure of how to gather that information from either of the above two queries and convert it into a System.Data.DbType or System.TypeCode.
Any help is greatly appreciated.
Links: MSDN: sp_columns, MSDN: Information Schema.Columns
Edit: I guess what I'm looking for is functionality similar to Type.GetType("TypeName") that would accept a SQL data type. For example, DbType.GetType("int") or DbType.GetType("varchar").
Edit: Links from Answer: MSDN: Enum.Parse Method
It's actually really easy to do :-) SqlDbType is an enum, and there's a nice static function on the Enum class which accomplishes just what your looking for:
private SqlDbType ConvertType(string typeName)
{
return (SqlDbType)Enum.Parse(typeof(SqlDbType), typeName, true);
}
With this, you should have no trouble converting the output from your INFORMATION_SCHEMA query into a collection of SqlParameters.

Resources