Data Transfer in AX - axapta

I just started a new Project _NewEnglandPatriots.
EDTs:
FirstName (extends Name)
SecondName(extends Name)
LastName (extends Name)
Position (String)
PlayerBirthday (Date)
JerseyNumber (Integer)
Tables:
SycTeamRoster (I've dragged all my EDTs to the "Fields" of the table)
Forms:
TeamRoster (I've dragged all the fields into my SimpleList design)
I have inserted the following player data to the form without a problem:
Thomas Edward
Patrick
Brady
12
Quarterback
03.08.1977
Next I wrote a Job insertTeamMembers, within which I insert the member with the following code:
static void insertTeamMembers(Args _args)
{
SycTeamRoster newEnglandTable;
container teammembers;
container conTake;
int i;
;
teammembers = [["Khashayar" ,"Goudarzi", 1, "Quarterback", 28,02,1990]];
ttsBegin;
for(i=1; i<=conLen(teammembers); i++)
{
conTake= conPeek(teammembers,i);
newEnglandTable.clear();
newEnglandTable.SycVorname = conPeek(teammembers,1);
newEnglandTable.SycNachname = conPeek(teammembers,2);
newEnglandTable.SycJerseyNumber = conPeek(teammembers,3);
newEnglandTable.SycPosition = conPeek(teammembers,4);
newEnglandTable.SycPlayerBirthday = conPeek(teammembers,5);
newEnglandTable.insert();
}
ttsCommit;
}
The problem is that I get the following data to the Form and Table:
FirstName: Khashayar
SecondName: empty, but because I left it that way
LastName: empty
JerseyNumber: 0
FieldPosition: 0
Birthday: empty
What is causing these empty fields in the table?

These lines are using teammembers instead of conTake
newEnglandTable.SycVorname = conPeek(teammembers,1);
Change to
newEnglandTable.SycVorname = conPeek(conTake,1);
And the way you have data entered in your nested container, specifically 28,02,1990 is going to be a problem.
This appears to be a learning exercise, so I don't want to solve the entire thing for you.

Related

X++ assign Enum Value to a table column

I am trying to pull the Enum chosen from a dialog and assign the label to a table's column.
For example: Dialog opens and allows you to choose from:
Surface
OutOfSpec
Other
These are 0,1,2 respectively.
The user chooses OutOfSpec (the label for this is Out Of Spec), I want to put this enum's Name, or the label, into a table. The column I'm inserting into is set to be a str.
Here's the code I've tried, without success:
SysDictEnum dictEnum = new SysDictEnum(enumNum(SDILF_ScrapReasons));
reason = dialog.addField(enumStr(SDILF_ScrapReasons),"Scrap Reason");
dialog.run();
if (!dialog.closedOk())
{
info(reason.value());
return;
}
ttsBegin;
// For now, this will strip off the order ID from the summary fields.
// No longer removing the Order ID
batchAttr = PdsBatchAttributes::find(itemId, invDim.inventBatchId, "OrderId");
orders = SDILF_BreakdownOrders::find(batchAttr.PdsBatchAttribValue, true);
if (orders)
{
orders.BoxProduced -= 1;
orders.update();
}
// Adding a batch attribute that will include the reason for scrapping
select forUpdate batchAttr;
batchAttr.PdsBatchAttribId = "ScrapReason";
//batchAttr.PdsBatchAttribValue = any2str(dictEnum.index2Value(reason.value()));
batchAttr.PdsBatchAttribValue = enum2str(reason.value());
batchAttr.InventBatchId = invDim.inventBatchId;
batchAttr.ItemId = itemId;
batchAttr.insert();
Obviously this is not the whole code, but it should be enough to give the issue that I'm trying to solve.
I'm sure there is a way to get the int value and use that to assign the label, I've just not been able to figure it out yet.
EDIT
To add some more information about what I am trying to accomplish. We make our finished goods, sometimes they are out of spec or damaged when this happens we then have to scrap that finished good. When we do this we want to keep track of why it is being scrapped, but we don't want just a bunch of random reasons. I used an enum to limit the reasons. When the operator clicks the button to scrap something they will get a dialog screen pop-up that allows them to select a reason for scrapping. The code will then, eventually, put that assigned reason on that finished items batch attributes so that we can track it later in a report and have a list of all the finished goods that were scrapped and why they were scrapped.
I'm not entirely sure of your question, but I think you're just missing one of the index2[...] calls or you're not getting the return value from your dialog correctly. Just create the below as a new job, run it, make a selection of Open Order and click ok.
I don't know the difference between index2Label and index2Name.
static void Job67(Args _args)
{
Dialog dialog = new dialog();
SysDictEnum dictEnum = new SysDictEnum(enumNum(SalesStatus));
DialogField reason;
SalesStatus salesStatusUserSelection;
str label, name, symbol;
int value;
reason = dialog.addField(enumStr(SalesStatus), "SalesStatus");
dialog.run();
if (dialog.closedOk())
{
salesStatusUserSelection = reason.value();
// Label
label = dictEnum.index2Label(salesStatusUserSelection);
// Name
name = dictEnum.index2Name(salesStatusUserSelection);
// Symbol
symbol = dictEnum.index2Symbol(salesStatusUserSelection);
// Value
value = dictEnum.index2Value(salesStatusUserSelection);
info(strFmt("Label: %1; Name: %2; Symbol: %3; Value: %4", label, name, symbol, value));
}
}

Creating a Kusto table with table name coming from query result

I would like to create a table the name of which comes from result of a query. Any very basic example will do. The result could be a single column , single row also. I just need a basic example so I can tweak and modify it as per my requirement.
any control command which creates a table requires the table name to be known in advance and part of the command's text.
you could run a 2-step flow programmatically, where:
the 1st step gets the table name (e.g. using a query),
the 2nd step generates the .create table or .set command string (based on the 1st), then invokes the command.
an example, using the .NET client library:
using Kusto.Data;
using Kusto.Data.Common;
using Kusto.Data.Net.Client;
using System.Linq;
namespace Playground
{
class Program
{
static void Main(string[] args)
{
const string clusterName = "myClusterName";
const string regionName = "westus";
const string databaseName = "myDatabaseName";
const string queryForTableName = "MyExistingTable | summarize count() by TableName | top 1 by count_ desc | project TableName";
var kcsb = new KustoConnectionStringBuilder($"https://{clusterName}.{regionName}.kusto.windows.net", databaseName).WithAadUserPromptAuthentication();
using (var queryProvider = KustoClientFactory.CreateCslQueryProvider(kcsb))
{
// step 1: get the table name, based on the result of a query
var tableName = queryProvider.ExecuteQuery<string>(queryForTableName).Single();
using (var adminProvider = KustoClientFactory.CreateCslAdminProvider(kcsb))
{
// step 2.1: generate the control command's text, using the value from step 1
var createTableCommand = CslCommandGenerator.GenerateTableSetCommand(tableName, "print value = 'This is a value in my new table'", isAsync: false);
// step 2.2: invoke the control command
adminProvider.ExecuteControlCommand(createTableCommand);
}
}
}
}
}

SQLIte not displaying all of the results correctly in ListView

I am having trouble with displaying the results in the search activity of my app. I wonder where it went wrong.
The aim of the function below is to search the input query of the user and find it in every files listed. But the results only matches one data eventhough the query is also present in the other files. Here is the code.
public void searchFiles(File[] filelist, String query, String querysearch, String[] namesOfFiles){
querysearch = "SELECT * FROM Data WHERE ObjectID = ? ";
int temp2 = filelist.length;
for (int i = (temp2-1); i >= 0; i--) {
if(!(filelist[i].getName().equals("DataObjectDB.db")) && !(filelist[i].getName().endsWith("-journal"))){
temp1 = filelist[i].getName();
namesOfFiles[i] = temp1.replaceAll(".db$", "");
Toast.makeText(getApplicationContext(),"Searching " + query + " in: " + namesOfFiles[i], Toast.LENGTH_SHORT).show();
DatabaseHelper db1 = new DatabaseHelper(getApplicationContext(),namesOfFiles[i]);
SQLiteDatabase sqldb = db1.getWritableDatabase();
cursor = sqldb.rawQuery(querysearch, new String[]{query});
Toast.makeText(getApplicationContext(),cursor.toString(), Toast.LENGTH_SHORT).show();
}
}
final ListView listView = (ListView) findViewById(R.id.results_listview);
SearchAdapter adapter = new SearchAdapter(this, R.layout.results_column, cursor,0 );
listView.setAdapter(adapter);
}
The searchFiles() function passes the filelist, query, querysearch and namesOfFiles where 1) filelist contains the list of files in the source folder 2) query is the user input he/she wants to search 3) querysearch is the select statement 3) namesofFiles is just an empty string.
I indicate a toast to see if the code traverses through all the folders. And yes it is. But I don't know why it is not displaying all the results.
Any help? Thanks!
Found an answer on different posts. Basically, you just have to use hashmap and arraylist first before setting up the adapter directly.

Technique to reduce load on server,while searching & comparing for particular item into large(10,000 entries) LIST object created at server side

I want to know that,
If we have LIST object created at server side which contains large amount of data entries like employess master data(10,000), & I want to give search option to search valid employee ID or name.
So I have tried to compare that entered text with that list of large entries in loop, which is obvious degrading performance.
So is there any option to better performace?
Thanks in advance.
Try this:
public List<Employee> SearchEmployee(string search, int pageNo, int pageLength)
{
MasterDataContext db = new MasterDataContext();
var searchResult = (from e in db.Employess
where (search == null ||
e.Name.ToLower().Contains(search.ToLower()))
select e).ToList();
int pageStart = (pageNo - 1) * pageLength;
var pageResult = from c in searchResult.Skip(pageStart).Take(pageLength)
orderby c.CardNo
select c;
return pageResult;
}
I hope it helps.

Creating a TreeView Nested Structure Using Self Referencing Table

I am trying to create a TreeView nested structure with the use of self referencing table fields. Here is a simple example:
Category 1
Product 1
Toy 1
Toy 2
Product 2
Toy 3
Toy 4
more categories..
The database table has a single table called "Category". The ParentCategoryId points to the Category which is the parent. So, for the Category 1 the ParentCategoryId is null since it is parent. For Product 1 the ParentCategoryId is that of the Category 1 id and for Toy 1 the ParentCategoryId is that for the Product 1 id.
I am using the following code but it does not generate the TreeView (ASP.NET) successfully.
public void BuildTree(List<Category> categories, TreeNode treeNode)
{
if (treeNode == null) return;
TreeNode tnAdd = null;
var categoryId = Guid.NewGuid();
foreach (var category in categories)
{
if (category.IsBaseCategory)
{
tnAdd = new TreeNode();
tnAdd.Text = category.Description;
BuildTree((from c in categories
where c.ParentCategoryId == category.CategoryId
select c).ToList<Category>(), tnAdd);
}
else
{
tnAdd = new TreeNode();
tnAdd.Text = category.Description;
BuildTree((from c in categories
where c.ParentCategoryId == category.CategoryId
select c).ToList<Category>(), tnAdd);
}
if (tnAdd != null)
treeNode.ChildNodes.Add(tnAdd);
}
}
Does this require recursion!
and here is the result I get:
80W
40W
40W
Light Bulbs
Flourecent
Incedecent
60W
80W
60W
Flourecent
40W
80W
60W
Incedecent
80W
40W
60W
What isn't successful?
If its because you see nothing ... I don't see where you're ever adding the root node to the actual tree control. tnAdd needs to be added to the tree control somewhere.
If it's because your not getting everything you expect: Unless you already have recursion going on somewhere and don't realize it, I can't see how the above code is ever going to get to the toy level. You say "base", then "child" in the above code which covers two levels. You have three levels in your sample data, so at some point you need to account for adding the toys. You can write it recursively if you need to have n levels. If you only have three levels, you can just repeat yourself.
----- UPDATES FOR OP UPDATES
Looking at your code, what you have is this:
for each category {
if it is base
add its children
else if it is not base
add its children
add it to the tree
}
This means every item is hit in the first foreach and added to the tree, rather than per level.
what you want is
for each category{
if it is base
add base's children
for each child [
add child's children
add child to the tree
]
add base the tree
}
Something closer to this (I don't have time to test right now, sorry) should come close to working
public BuildTreeTop(List<Category> categories, TreeNode treeNode)
{
BuildTree((from c in categories
where c.IsBaseCategory == true
select c).ToList<Category>(), categories, tnAdd);
}
public void BuildTree(List<Category> currentLevel, List<Category> allCategories, TreeNode treeNode)
{
if (treeNode == null) return;
TreeNode tnAdd = null;
var categoryId = Guid.NewGuid();
foreach (var category in currentLevel)
{
tnAdd = new TreeNode();
tnAdd.Text = category.Description;
BuildTree((from c in allCategories
where c.ParentCategoryId == category.CategoryId
select c).ToList<Category>(), allCategories, tnAdd);
if (tnAdd != null)
treeNode.ChildNodes.Add(tnAdd);
}
}

Resources