Announcements
Hi All, I am new to Business Connector in AX.
I try to display customer Id and customer Name in Console window. I get the error as Supplied Method Arguments Are not Valid .
I am sharing my code , correct me where i am wrong.
Thanks In Advance,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Dynamics.BusinessConnectorNet;
namespace BCClass_Demo
{
class Program
{
static void Main(string[] args)
{
Axapta ax;
AxaptaRecord axRecord,axRecord1;
String tableName = "CustTable";
String tableName1 = "DirPartyTable";
String sqlStmt = ("Select * from %2 join %1 where %2.RecId == %1.party");
Object cusid , name;
try
{
ax = new Axapta();
ax.Logon(null, null, null, null);
axRecord = ax.CreateAxaptaRecord(tableName);
axRecord1 = ax.CreateAxaptaRecord(tableName1);
axRecord.ExecuteStmt(sqlStmt);
while (axRecord.Found)
{
cusid = axRecord.get_Field("AccountNum");
name = axRecord1.get_Field("Name");
Console.WriteLine("CustAccountNum \t CustomerName" );
Console.WriteLine(cusid + "\t\t " +name);
axRecord.Next();
}
Console.ReadKey();
}
catch (Exception e)// I caught error as Supplied Method Arguments Are not Valid
{
Console.WriteLine("error" + e);
}
}
}
}
*This post is locked for comments
Hi Rusty Ryan,
Can you post full method's code to see how are you using this statement.
Hi ievgen, Can you tell me the ans for my above question?
Yes Absolutely , and as i said changed back to while(axRecord.Found).. inside my loop i have name = axRecord1.get_Field("Name");// This gives me correct customer name bcoz of the sql statement , no need to use both..
"Select * from %1 join %2 where %1.Party== %2.RecId"
Right Now i am asking , why this statement won't work ??
"Select * from %2 join %1 where %2.RecId == %1.party"
Hi Rusty,
Ax record belongs to Custtable. Axrecord1 belongs to Dirpartytable when you are looping in Only Axrecord1 it will not have the table fields of Axrecord .So try to use both
False Alarm ievgen, Thanks for your support ,, I changed my SQL stmt to
"Select * from %1 join %2 where %1.Party== %2.RecId" and my changed my while loop back as while(axRecord.Found) and it works perfectly.
But if u give me heads up on why this stmt won't work
"Select * from %2 join %1 where %2.RecId == %1.party"
will help me .. Thanks in Advance
I have changed the while loop as while(axRecord1.Found) which is now infinite.. and it brings only the first customer name
Hi ievgen,
Thank you for the heads up.. how silly of me, missed that ...
Thanks again.. :)
And another quick question, As i said i am trying to print the customer id and customer name , Is my Relation is Correct? Bcoz when i run i getting infinite while loop and im getting the first customer name only .. Pls Advice
Hi Rusty Ryan,
Please look at ExecuteStmt function description msdn.microsoft.com/.../microsoft.dynamics.businessconnectornet.axapta.executestmt.aspx you should pass record as second parameter as well.
André Arnaud de Cal...
294,002
Super User 2025 Season 1
Martin Dráb
232,852
Most Valuable Professional
nmaenpaa
101,158
Moderator