AX 2012 how to set args record datasource in X++ - x++

Can anyone tell me what should I do in X++ to get a NOT null value from args.record().datasource() method after executing the following statements:
PurchTable purchTable;
args.record(purchTable);
if(args.record().datasource()) //this condition fails because of null value
{
//I have to reach here
}
I know that the same code works fine when it is called from Form but my scenario is that I have to execute this code from within X++. Please help!

args.record().datasource() will retrieve a form datasource. Here, you are using a table buffer only. That's why you don't have anything.
If you want to retrieve the table buffer, you might go this way:
PurchTable purchTable;
PurchTable argPurchTable;
select firstOnly purchTable;
args.record(purchTable);
if (args.record() && args.dataset() == tableNum(PurchTable))
{
argPurchTable = args.record();
//do something
}
Regards,
Geoffrey

Related

How can I check results for select statement in MVC?

Hi this is the SP I have :
USE [Tracker_Entities]
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[uspHub]
#id int
AS
BEGIN
SELECT DISTINCT table1.UID, table1.url, Scope.ID
FROM table1 INNER JOIN
Scope ON table1.UID = Scope.newBrand
WHERE (table1.value = 0) AND (Scope.ID = #id)
ORDER BY table1.url
END
GO
When i run this SP in sql server by passing ID as parameter i am getting expected result. Now I need to check this SP in mvc. This is the way I am calling this SP in my MVC :
using (var ctx = new database_Entities())
{
int ID = 122;
ctx.uspHub(ID);
ctx.SaveChanges();
}
But when I put breakpoint in using statement and check for results, it is not displaying any results. I am struggling here for long time and i am not getting proper solution for this. So what are the steps in MVC to check results for SP which has select statements??
Update :
I got solution for this after using tolist. Now i am getting three results in list and i need to grab one result that is URL and pass it as input parameter.
My code :
int ID = 413;
var x = ctx.uspdHub(ID).ToList();
Here x has 3 results. I need to take one result from it.I tried doing x. but it doesn't show results after i type dot. How can i achieve this??
You have to Get the result into proper model/object.
List<YourEntity> model;
using (var ctx = new database_Entities())
{
int ID = 122;
model = ctx.uspHub(ID).toList();
//ctx.SaveChanges(); - no need to call SaveChanges
// - as you are not updating anything
}
Go through this article if you need more info. Call Stored Procedure From Entity Framework (The code above will work anyways...)
use...
using (var ctx = new database_Entities())
{
int ID = 122;
var result = ctx.uspHub(ID);
}
and add a break after the result to see whats in the result variable. Obviously, the sope of result will need to be moved, but I'm only showing here how you can see the data returned.
Try to use something like this:
using (var dataContext= new database_Entities())
{
int ID = 122;
SomeEntity[] result = dataContext.Database.SqlQuery<SomeEntity>("[dbo].[uspHub] #id",new SqlParameter("#id", ID)).ToArray();
}
It is good for me. I have used ORM EntityFramework to connect with DB.

How can I update table in Entity framework?

I am calling a web service from my MVC project and if it is successful then it returns process complete. This result, I am storing in variable called y.
var y = Here pass required parameters and if it is successfull store result in y
when I put breakpoint here and if process complete, I can see result in var y.
So if process complete I need to update my table. For this can I do like this ?
if( y = "Process complete")
{
update table code here
}
and I don't know how to update table in Entity Framework. Here I need to update table called table1 and set column2 = 1, column 3 = value of column 4 where column 1 = value of column 1.
What I know for this is :
UPDATE tableName
SET column2 = 1, column3 = context.FirstOrDefault().column4
WHERE column1 = context.FirstOrDefault(). column1
Update :
Hi i got to know how to write code to update table.But when i put break-point and come to savechanges method i am getting Property export is part of the objects key information and cannot be modified error.
This is the code i am using to update my table :
var rec = (from s in geton.table_1
where s.on_id == geton.table_1.FirstOrDefault().on_id
select s).FirstOrDefault();
rec.export = 1;
rec.on_date = geton.table_1.FirstOrDefault().on_date;
geton.SaveChanges();
A new entity can be added to the context by calling the Add method on DbSet. This puts the entity into the Added state, meaning that it will be inserted into the database the next time that SaveChanges is called.
For example:
using (var context = new YourContext())
{
var record = new TypeName { PropertyName = "Value" };
context.EntityName.Add(record );
context.SaveChanges();
}
For More Info :
http://msdn.microsoft.com/en-us/library/bb336792.aspx
http://msdn.microsoft.com/en-us/data/jj592676.aspx
http://www.entityframeworktutorial.net/significance-of-savechanges.aspx
Hi i got to know how to write code to update table.But when i put break-point and come to savechanges method i am getting Property export is part of the objects key information and cannot be modified error.
That sounds more like a Key error. Are you sure you have put a primary key on that table?
If not then EF just uses the whole table as the key essentially

Grails: ArrayList - Retrieval Speed

I'm working on speed issues with a currently working method that finds a specific attribute collection within an ArrayList. Depending on the size, it can take longer than 7 seconds to find the value in the list.
I need to speed up this process, so I can deal with larger volumes of data. Any assistance would be greatly appreciated. Here is my example;
Method:
public ArrayList getIntegrationTag(String attribute) {
return crmMapping?.findAll { it.get("ATTRIBUTE") == attribute }?.collect{
it.INTEGRATION_TAG
}?.unique()
}//end getIntegrationTag(String attribute)
crmMapping content
"[{ATTRIBUTE=AcademicIndex, INTEGRATION_TAG=Contact~nAcademic_Index},
{ATTRIBUTE=AcademicInterest,
INTEGRATION_TAG=Contact~msplAcademic_Interest},........]"
the findAll loops over each record, then the collect loops over each record, then unique loops over each record again.
Try...
Set result = [] as Set
for(element in crmMapping) {
if(element.get("ATTRIBUTE") == attribute) {
result << element.INTEGRATION_TAG
}
}
return (result as ArrayList)
This will only loop once it it will be unique as it was added to a Set
Do the following once
def crmMappingMap = crmMapping.groupBy({ it.ATTRIBUTE })
Then you have a map of all same attribute instances and can access it using crmMappingMap[attribute].INTEGRATION_TAG, which will return the desired array, like this:
public ArrayList getIntegrationTag(String attribute) {
crmMappingMap[attribute].INTEGRATION_TAG.unique()
}
Always keep a map, then speed of access will be fast enough.

groovy way of if(var) fn(var)

i want to know is there any groovier way of code below:
def dataList = OperLog.createCriteria().list(max:params.max, offset:params.offset) {
if(params.relationId){
eq('relationId',params.long('relationId'))
}
order(params.sort, params.order)
}
such as someVar?.someMethod
is there any sugar of don't call a method where it's params is null
You could do:
params.relationId?.with { rid ->
println rid
}
And the code inside the with block will not be executed if params.relationId is null...
However, I'd argue that your original code is more obvious in its intentions, and you won't have to try and work out what it is doing when you come to review it at a later date ;-)
is there any groovier style of this?
def list = [vo1,vo2,vo3]
list.each{
someMethod(it)
}
just like
list*.toString()

how do i iterate the tables parameters which is present under the main table?

In lua ,im calling a function which returns a table variable that contains many parameter internally..but when i get that value i couldnt access the paramter which is present in the table. I can see the tables parameter in the original function in the form of
[[table:0x0989]]
{
[[table:0x23456]]
str = "hello"
width = 180
},
[[table:0x23489]]
{
str1 = "world"
}
it shows like this.but when it returns once i can able to get the top address of table like [[table:0x0989]]..when i tried acessing the tables which is present inside the main table.it is showing a nil value...how do i call that ?? can anyone help me??
If I'm reading it correctly you're doing this:
function my_function ()
--do something
return ({a=1, b=2, c=3})
end
From that you should be able to do this:
my_table = my_function()
then
print(my_table.a) --=> 1
print(my_table.b) --=> 2
print(my_table.c) --=> 3

Resources