Category Archives: C# Development
AX Update Example
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
// Create an Axapta record for the StateAddress table. axRecord = ax.CreateAxaptaRecord(tableName); // Execute a query to retrieve an editable record where the name is MyState. axRecord.ExecuteStmt(\"select forupdate * from %1 where %1.Name == \'MyState\'\"); // If the record is found then update the name. if (axRecord.Found) { // Start a transaction that can be committed. ax.TTSBegin(); axRecord.set_Field(\"Name\", \"MyStateUpdated\"); axRecord.Update(); // Commit the transaction. ax.TTSCommit(); } |
Posted in C# Development
Comments Off on AX Update Example
AX BC- Query with Joins
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
try { AxaptaRecord[] tableArray = new AxaptaRecord[2]; AxaptaRecord APMObjectTableRecord = DynAx.CreateAxaptaRecord("APMObjectTable"); AxaptaRecord WarrantyTableRecord = DynAx.CreateAxaptaRecord("WarrantyInvoiceTable"); tableArray[0] = APMObjectTableRecord; tableArray[1] = WarrantyTableRecord; DynAx.ExecuteStmt("select * from %1 join %2", tableArray); while (APMObjectTableRecord.Found) { string Id = (string)APMObjectTableRecord.get_Field("APMObjectId").ToString(); string Amount = (string)WarrantyTableRecord.get_Field("Amount").ToString().ToString(); APMObjectTableRecord.Next(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Don't Panic!"); } |
Posted in C# Development
Comments Off on AX BC- Query with Joins
AX BC- Read a Record
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
try { DynRec = DynAx.CreateAxaptaRecord("smmBusRelTable"); string fieldName = ("Status"); string fieldValue = ("Active"); DynRec.ExecuteStmt(string.Format("select * from %1 where %1.{0} == '{1}'", fieldName, fieldValue)); List<String> QueryList = new List<string>(); while (DynRec.Found) { QueryList.Add((string)DynRec.get_Field("BusRelAccount")); DynRec.Next(); } MainGrid.DataSource = (from item in QueryList select new { item }).ToList(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Don't Panic!"); } |
Posted in C# Development
Comments Off on AX BC- Read a Record
AX BC- Update a Record
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
try { // Create an Axapta record for the StateAddress table. DynRec = DynAx.CreateAxaptaRecord("APMObjectTable"); // Execute a query to retrieve an editable record where the name is MyState. DynRec.ExecuteStmt("select forupdate * from %1 where %1.APMObjectId == 'HLH000001'"); // If the record is found then update the name. if (DynRec.Found) { // Start a transaction that can be committed. DynAx.TTSBegin(); string _text = @""; _text += "Line One\n"; _text += "Line Two\n"; _text += "Line Three\n"; _text += "Line Four\n"; DynRec.set_Field("APMObjectDescription", _text); DynRec.Update(); // Commit the transaction. DynAx.TTSCommit(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Don't Panic!"); } |
Posted in C# Development
Comments Off on AX BC- Update a Record
AX BC- Log Off
|
1 2 3 4 5 6 7 8 9 |
try { DynAx.Logoff(); Application.DoEvents(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Don't Panic!"); } |
Posted in C# Development
Comments Off on AX BC- Log Off
AX BC- Log On
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
try { StatusBar.Text = "Logging On..."; Application.DoEvents(); // Authenticate the user and establish a session. DynAx.Logon(null, null, null, @"\\ediaxsql01v\DynamicsAX\Application\Share\config\64bit\AX09SP1-Capital-TEST.axc"); Application.DoEvents(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Don't Panic!"); } |
Posted in C# Development
Comments Off on AX BC- Log On
AX BC- Declaring
Make sure that you add the reference; Microsoft.Dynamics.BusinessConnectorNet
|
1 2 3 4 5 6 7 8 |
using Microsoft.Dynamics.BusinessConnectorNet; Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta(); Microsoft.Dynamics.BusinessConnectorNet.AxaptaRecord DynRec; Microsoft.Dynamics.BusinessConnectorNet.AxaptaRecord DynRecView; |
Posted in C# Development
Comments Off on AX BC- Declaring
Parse Field Data
Function to parse data from a field, checking for nulls.
|
1 2 3 4 5 6 7 8 |
private string ParseField(object _value) { // Does check for nulls in a data field and convert to a blank string if (_value is DBNull || _value == null) return @""; else return _value.ToString(); } |
Posted in C# Development
Comments Off on Parse Field Data
Basic Class
Basic class example.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
[Serializable()] public class classFieldList { private string _FieldName; private string _FieldType; public string FieldName { get { return _FieldName; } set { _FieldName = value; } } public string FieldType { get { return _FieldType; } set { _FieldType = value; } } } |
Posted in C# Development
Comments Off on Basic Class
Entity- Multiple field query
Entity query to a list
|
1 2 3 |
Grid.DataSource = (from status in MyQuery orderby status.ServiceObjectStatus select status.ServiceObjectStatus).ToList(); |
Posted in C# Development
Comments Off on Entity- Multiple field query