cancel
Showing results for 
Search instead for 
Did you mean: 

Using SQL query in .NET dynamic code for B1 UP validation

former_member675796
Participant
0 Kudos

Hi Experts!

I have some code that creates a SQL string and then uses it as a query with the 'Recordset.DoQuery' method of the SAP Business One .NET framework.

I have been following an online tutorial. However, I am not able to get the code to run and assign the value correctly.

Also, is it not possible to use a value from the UI in the dynamic .NET code in this way? Do I not have access to those variables?

Any help would be much appreciated. Here is my code:

string query = "SELECT LastPurPrc FROM OITM WHERE ItemCode LIKE $[$4.0.0]";

SAPbobsCOM.Recordset rs = (SAPbobsCOM.Recordset)company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)

int result = rs.DoQuery(query);

Thanks again,

Alex

View Entire Topic
former_member675796
Participant
0 Kudos

Hi Johan,

Yes, I know about the issue with the '$[$4.0.0]' being part of the string. I was just showing my code like that to illustrate what I was trying to do (i.e. use the UI value in the .NET dynamic code).

Yes, I have tried what you suggested (and rightly pointed out probably wouldn't work!) by putting the UI value in the code like " + $[$4.0.0] ". I also tried it like " + $[$4.0.0] + " but yes, it doesn't work. Is there no way to access these values in dynamic .NET code?

What I am trying to do, specifically, is create a validation for when a Purchase Price on an A/P invoice or a purchase order is very different to the Last Purchase Price in the database - and flag this to the user.

I'm using Dynamic Code for this because I thought it was the best method. Also, I'm experimenting with .NET code in SAP.

Thanks,

Alex