How to use notanyof in nlobjSearchFilter - suitescript

var ids = ['1', '2', '3'];
var filters = new Array();
filters[0] = new nlobjSearchFilter('mainline', null, 'is', 'T');
filters[4] = new nlobjSearchFilter('entity', null, 'notanyof', ids);
var searchResult = nlapiSearchRecord('creditmemo', null, filters, columns);
Hello I'm trying to list all credit memos but where the customer ID is not 1,2 or 3?
Can you help me? Thanks

The proper operator is "noneof".
new nlobjSearchFilter('entity',null,'noneof',[1,2,3]);

Related

Drupal 8: convert node id from string to integer

Retrieve a node based on condition:
$query = \Drupal::entityQuery('node')
->condition('type', 'my_content_type')
->condition('title', 'my node title');
$nid = $query->execute();
The result of $nid is the correct node ID but the format is a string, (es: "123")
When I want to load the node by its ID, I write:
$node_id = Node::load($nid);
Doing this, the result I get is NULL because the variable $nid is holding a string (not integer).
If I write the code like this:
$node_id = Node::load(123);
I get the node loaded.
How can I convert the variable string ($nid) as an integer ?
I tried:
$nid_int = (int) $nid;
$node_id = Node::load($nid_int);
also I tried:
$nid_int = intval($nid);
$node_id = Node::load($nid_int);
But I alwas get result NULL
Thanks for your help
You can't use Node::load($nid); directly, because the $query->execute() return an array like ['vid' => "nid"].
$query = \Drupal::entityQuery('node')
->condition('type', 'my_content_type')
->condition('title', 'my node title');
$nids = $query->execute();
$nid = (int)array_shift($nids);
Can try:-
$nid_string = $nid->__toString();
$node_id = Node::load((int) $nid_string);

Display result of linq query randomly in listview in Asp.net C#

var getquest = (from q in dc.Exam_Questions
where q.ExamNumber == int.Parse(Examnumber)
select new
{
QuestionTitle = q.QuestionTitle,
correctanswers = q.correctanswers,
ID = q.ID,
});
ListView1.DataSource = getquest;
ListView1.DataBind();
How to display result of linq query randomly in listview in Asp.net C#?
You can create a random data by adding a guid property to your query. After that you order the result by this new property.
var getquest = (from q in dc.Exam_Questions
where q.ExamNumber == int.Parse(Examnumber)
select new
{
RandomId = Guid.NewGuid(),
QuestionTitle = q.QuestionTitle,
correctanswers = q.correctanswers,
ID = q.ID,
});
ListView1.DataSource = getquest.OrderBy(p => p.RandomId).ToList();
ListView1.DataBind();

how to assign value to entity got from database

I have a linq query like below:
public IQueryable<vmEmp> GetEmp(int crewid)
{
var dt = new EmpEntities();
var e = from t in dt.tblEmp
where (t.CrewId == crewid)
select new vmEmp
{
Id = -1,
Crew = t.crewid,
Name = t.Name,
Address = t.Address
};
return e;
}
I hope can make the Id auto decrease by 1 till end of the employee.
like first's Id is -1, second's is -2, third is -3 ...
How to do that here? Thanks a lot
If this was LINQ-to-objects, you could use this overload of Select:
var dt = new EmpEntities();
var e = dt.tblEmp
.Where(t => t.CrewId == crewid)
.Select((t,index) => new vmEmp
{
Id = -index - 1,
Crew = t.crewid,
Name = t.Name,
Address = t.Address
});
But EF doesn't suport this, because the indexer can't be translated into SQL. So you need a work-around:
var dt = new EmpEntities();
var e = dt.tblEmp
.Where(t => t.CrewId == crewid)
.Select(t => new
{
Id = 0,
Crew = t.crewid,
Name = t.Name,
Address = t.Address
}
.AsEnumerable() // Continue in memory
.Select((t,index) => new vmEmp
{
Id = -index - 1,
Crew = t.Crew,
Name = t.Name,
Address = t.Address
});
Side note: it's recommended to put dt in a using construct.
Use a counter variable and decrease it for every record while you project it to your custom POCO.
public IQueryable<vmEmp> GetEmp(int crewid)
{
int counter=0;
var dt = new EmpEntities();
//load the items to a list of anonymous type
var eList = from t in dt.tblEmp
where (t.CrewId == crewid)
.Select(s=>
new { Id = 0,
Crew = s.crewid,
Name = s.Name,
Address = s.Address
}).ToList();
var e=eList.Select(x=> new vmEmp
{
Id = --counter,
Crew = x.Crew,
Name = x.Name,
Address = x.Address
});
return e.AsQueryable();
}

How to calculate count on of table column using group by clause in linq

I'm new to linq.
In c# I'm doing as follows to get the count of one column.
SELECT DispatcherName,
ActivityType,
CONVERT(BIGINT,COUNT(ActivityType)) AS Total
FROM ACTIVITYLOG
GROUP BY DispatcherName,
ActivityType
ORDER BY Total DESC
Can any one tell m,how I can achieve the same thing using LINQ.
Update:
HI I did as follows and got the reslut.
But I'm not able to convert result to datatable.
this is how I did.
here dt is datatabe with two columns Dispatchername and ActivityType.
var query1 = from p in dt.AsEnumerable()
group p by new
{
DispatcherName = p.Field<string>("Dispatchername"),
Activity = p.Field<string>("ActivityType"),
}
into pgroup
let count = pgroup.Count()
orderby count
select new
{
Count = count,
DispatcherName = pgroup.Key.DispatcherName,
Activity = pgroup.Key.Activity
};
pls help me out asap.
from c in ACTIVITYLOG
group c by new {c.DispatcherName, c.ActivityType} into g
orderby g.Count() descending
select new { g.Key.DispatcherName, g.Key.ActivityType, Total = g.Count() }
If you want your results returned back to a DataTable, one option is to use the CopyToDataTable method.
Here's a live example: http://rextester.com/XHX48973
This method basically requires you to create a dummy table in order to use its NewRow method - the only way to create a DataRow, which is required by CopyToDataTable.
var result = dt.AsEnumerable()
.GroupBy(p => new {
DispatcherName = p.Field<string>("DispatcherName"),
Activity = p.Field<string>("ActivityType")})
.Select(p => {
var row = dummy.NewRow();
row["Activity"] = p.Key.Activity;
row["DispatcherName"] = p.Key.DispatcherName;
row["Count"] = p.Count();
return row;
})
.CopyToDataTable();
Perhaps a better way might be just fill in the rows directly, by converting to a List<T> and then using ForEach.
DataTable dummy = new DataTable();
dummy.Columns.Add("DispatcherName",typeof(string));
dummy.Columns.Add("Activity",typeof(string));
dummy.Columns.Add("Count",typeof(int));
dt.AsEnumerable()
.GroupBy(p => new { DispatcherName = p.Field<string>("DispatcherName"),
Activity = p.Field<string>("ActivityType")})
.ToList()
.ForEach(p => {
var row = dummy.NewRow();
row["Activity"] = p.Key.Activity;
row["DispatcherName"] = p.Key.DispatcherName;
row["Count"] = p.Count();
dummy.Rows.Add(row);
});
Live example: http://rextester.com/TFZNEO48009
This should do the trick:
IList<ACTIVITYLOG> allActivityLogs;
var result = (from c in allActivityLogs
select new
{
DispatcherName = c.DispatcherName,
ActivityType = c.ActivityType,
Total = c.ActivityType.Count
}).OrderByDescending(x => x.Total)
.GroupBy(x => new { x.DispatcherName, x.ActivityType });
You only need to substitute the allActivityLogs collection with the actual collection of your entities.

JSON Array in Flex

I have code:
api_result = '{"response":[{"uid":1969258,"first_name":"Walle","last_name":"Woo"}]}';
var myobj:Object = JSON.decode(api_result);
So, how I can get uid, first_name and last_name from "response" array?
var UID:Object = myobj.response[0].uid;
var firstName:Object = myobj.response[0].first_name;
var lastName:Object = myobj.response[0].last_name;

Resources