I have created a dynamic query which can return a dataset from an external BAQ. I want the dyanmic query to only return the records which meet the parameters I have parsed.
This is the code I have so far:
// DynamnicQuery for BAQ
Epicor.Mfg.Core.Session epiSession = default(Epicor.Mfg.Core.Session);
epiSession = (Epicor.Mfg.Core.Session)POEntryForm.Session;
DynamicQuery dynamicQuery = new Epicor.Mfg.BO.DynamicQuery(epiSession.ConnectionPool);
//Build Data Set
QueryExecutionDataSet executionDS = new QueryExecutionDataSet();
//Build parametors
QueryExecutionDataSet parameters = new QueryExecutionDataSet();
DataRow paramRow = parameters.ExecutionParameter.NewRow();
paramRow["ParameterName"] = "POSuggestionsView.PartNum";
paramRow["ParameterValue"] = "10050886";
paramRow["ValueType"] = "nvarchar(50)";
paramRow["IsEmpty"] = "False";
paramRow["RowIdent"] = "";
paramRow["RowMod"] = "";
paramRow["DBRowIdent"] = new byte[0];
parameters.ExecutionParameter.Rows.Add(paramRow);
// Out variable which indicates if more results are available (likely for use with topNRecords)
bool hasMoreRecords = false;
//Executed named BAQ with parameter...
DataSet results = dynamicQuery.ExecuteByIDParametrized("AD-999-SB_POSuggestion", parameters, "", 0, out hasMoreRecords);
//Message Each Description....
MessageBox.Show("Number of rows in Results = " + results.Tables["Results"].Rows.Count.ToString());
foreach (DataRow item in results.Tables["Results"].Rows)
{
MessageBox.Show("Row Value = " + item["POSuggestionsView.PartNum"].ToString());
}
The code I have created still returns all of the values from the table without restricting the returned rows to the ones which meet the condition of the parameter. Can anyone help me as to why this is happening please?
You need to create a Parameter in the BAQ.
Open the BAQ editor and navigate to the Phrase Build tab, select the table you want to add the parameter to.
Add a new criteria to the table in the section below, the filter type will be "Specified Parameter". Take note of the parameter name.
Save the BAQ.
Back in your customization modify the paramRow["ParameterName"] = the parameter name you created in the BAQ.
Related
I have sub grid called track and location in event entity. Now I want to retrieve the name of the sub grid values and store that values in the text field.In pathway List field I need to add track name as comma separated if it is associate. If it is disassociate I need to remove the particular value form text field.I am new to plugin. I tried query expression but I don't have any common filed for track and event entity to use filter condition. Can u any one suggest the way to achieve this quickly.
I tried below code:
if (context.MessageName.ToLower() == "associate")
{
// Obtain the target entity from the input parameters.
Entity eventEntity = new Entity("leap_event");
var pathwayList ="" ;
QueryExpression query = new QueryExpression("leap_event");
query.ColumnSet = new ColumnSet(true);
LinkEntity linkEntity1 = new LinkEntity("leap_event", "leap_leap_event_leap_location", "leap_eventid", "leap_eventid", JoinOperator.Inner);
LinkEntity linkEntity2 = new LinkEntity("leap_leap_event_leap_location", "leap_location", "leap_locationid", "leap_locationid", JoinOperator.Inner);
linkEntity1.LinkEntities.Add(linkEntity2);
query.LinkEntities.Add(linkEntity1);
linkEntity2.LinkCriteria = new FilterExpression();
linkEntity2.LinkCriteria.AddCondition(new ConditionExpression("", ConditionOperator.Equal, ""));
EntityCollection collRecords = service.RetrieveMultiple(query);
tracingService.Trace("load");
for (int i = 0; i < collRecords.Entities.Count; i++)
{
tracingService.Trace("load1");
var result = collRecords.Entities[i].GetAttributeValue<string>("leap_name");
Console.WriteLine(result);
pathwayList += result + ",";
tracingService.Trace("pathwayName" + pathwayList);
eventEntity["leap_pathwayList"] = pathwayList;
}
}
you will have to use alias for your linked Entity. Take a sample example below.
I have Account Entity--> (N:N) list member Entity--> (N:N) List Entity.
In your case it would be
leap_event Entity--> (N:N) leap_leap_event_leap_location Entity--> (most probably N:N or 1:N) leap_event_leap_location entity.
In addition when you retrieve attribute you will have to use GetAttributeValue<AliasedValue> Take a look at this article it will help you understand
// Instantiate QueryExpression query
var query = new QueryExpression("account");
// Add columns to query.ColumnSet
query.ColumnSet.AddColumns("name", "accountid");
// Add link-entity listmemberentity
var listmemberentity = query.AddLink("listmember", "accountid", "entityid");
listmemberentity.EntityAlias = "listmemberentity";
// Add link-entity listentity
var listentity = listmemberentity.AddLink("list", "listid", "listid");
listentity.EntityAlias = "listentity";
// Add columns to listentity.Columns
listentity.Columns.AddColumns("listname");
It is not necessary to use linkentity.
The QueryExpression must be performed directly on the associated entity, with filter on lookup field (I assume "leap_eventid" field on "leap_location" entity) :
if (context.MessageName.ToLower() == "associate")
{
var query = new QueryExpression("leap_location");
query.ColumnSet.AddColumn("leap_name");
// Lookup filter
query.Criteria.AddCondition(new ConditionExpression("leap_eventid", ConditionOperator.Equal, context.TargetEntity.Id));
// Optional statecode filter
query.Criteria.AddCondition(new ConditionExpression("statecode", ConditionOperator.Equal, 0));
var collRecords = service.RetrieveMultiple(query);
if (collRecords.Entities.Count > 0)
{
var pathwayList = string.Empty;
foreach (var location in collRecords.Entities)
{
pathwayList += location.GetAttributeValue<string>("leap_name") + ",";
tracingService.Trace($"pathwayName {pathwayList}");
}
}
var eventEntity = new Entity("leap_event", context.TargetEntity.Id)
{
["leap_pathwayList"] = pathwayList
};
service.Update(eventEntity); // Update required for PostOperation Plugin
}
My result set is not sorting. How do I set up OrderBy for type System.Linq.GroupedEnumerable
I've converted an application from Core 1.1 to 2.2. Everything ported over fine except one piece of logic that:
1) takes a response from a service call maps it to a GroupedEnumerable
2) takes the grouped set and passes it to a function that maps it to an object of type System.Linq.Enumerable.SelectEnumerableIterator.
The resulting object is properly populated but not sorted. I have tried the order by in the function parameter call and as a separate process afterwards.
//response = {myService.myClient.SearchNominationsResponse}
//groupedSet = {System.Linq.GroupedEnumerable<ServiceClients.myClient.NominationObject, long>}
//result = {System.Linq.Enumerable.SelectEnumerableIterator<System.Linq.IGrouping<long, ServiceClients.myClient.NominationObject>, app.ViewModels.EvaluationSummary>}
public IEnumerable<EvaluationSummary> GetEvaluationSummaries(string sortBy, string sortOrder, Filter filter = null)
{
var request = Mapper.MapSearchNominationRequest(filter);
request.IsDetailed = false;
var response = myService.SearchNominationsAsync(request).GetAwaiter().GetResult();
var groupedSet = response.mySet.GroupBy(n => n.SetId);
// I get a proper result but it is not sorted
var result = groupedSet.Select(
g => Mapper.MapEvaluationSummary(
g.OrderBy(g2 => sortBy + " " + sortOrder)
.Last()));
// Still not sorting
result = result.OrderBy(r => sortBy + sortOrder);
return result;
}
public EvaluationSummary MapEvaluationSummary(SetObject setIn)
{
var eval = new EvaluationSummary
{
setDate = setIn.Date,
setId = setIn.Id,
setTypeId = setIn.TypeId,
setTypeDescription = setIn.TypeDescription,
setStatusId = setIn.StatusId,
setStatusDescription = setIn.StatusDescription,
setBy = setIn.Manager,
setEmployee = setIn.employee
};
}
So in my view I have columns that list Date, Id, setEmployee. I can click on these values to issue a sort pattern and I can see that the sortBy and sortOrder variables are being passed in with proper values but the sorting is not happening.
I expect 'William' to appear before 'Bill' and then Bill to appear before 'William' when toggling the employee column header in my view.
Based off of the previous answers, I'm still not sure if I can substitute a property name in the LINQ with a variable. To fix my problem and move on I've implemented JS logic to sort my table headers. We had a custom JS that we use to format tables in our apps but it seems the sort functionality never worked. Anyway not an answer to my question but this is how I solved the problem:
Logic can be found at:
http://www.kryogenix.org/code/browser/sorttable/
-HaYen
When adding records to a set, the resulting keys variable contains only one empty string, instead of the expect "i1".
var workspace = new GAMSWorkspace("TestWorkspace");
var database = workspace.AddDatabase();
var set = database.AddSet("TestSet", 1);
var record = set.AddRecord("i1");
var keys = record.Keys;
database.Export("TestDb");
What can cause this problem running the version Assembly GAMS.net4, Version=28.2.0.0
When I export the database to a .gdx file, the set contains the element i1.
How did you check, that the keysvariable does not contain the expected string? The record.Keys property returns a string[]. And if I add a WriteLine to your example, I get the expected string:
var database = ws.AddDatabase();
var set = database.AddSet("TestSet", 1);
var record = set.AddRecord("i1");
var keys = record.Keys;
Console.WriteLine(keys[0]);
Output:
i1
I have two custom objects. The parent object is an Order, and it has a list of type Part associated with it. I'm trying to get the list of Parts with a value "Inventory Item" in one field, but only for a particular Order.
I have the name and numeric internalId of the Order available,but the problem is those aren't (as far as I can tell) searchable "fields", there is no "internalId" to provide to tell it to search on one of those.
In the code below, if I don't include the attempt to search on the Order it works fine. I can get all the Parts with a type of "Inventory Item".
I think I need to use a joined search? My attempt at it is below. This produces a SOAP error at runtime:
Additional information: org.xml.sax.SAXException: 'customizationRef' on
{urn:common_2015_1.platform.webservices.netsuite.com}CustomSearchJoin is
required
Code
private static SearchResult NetSuiteSearchOrderItems(NetSuiteService netSuiteService, string order_name, string order_internalId)
{
CustomRecordSearch searchParts = new CustomRecordSearch();
CustomRecordSearchBasic basicRecordSearchParts = new CustomRecordSearchBasic();
basicRecordSearchParts.recType = new RecordRef { internalId = "64" }; //"Order Item" NetSuite Type ID
//adding a search filter on a String Custom Field
SearchStringCustomField partTypeFieldSearch = new SearchStringCustomField();
partTypeFieldSearch.#operator = SearchStringFieldOperator.#is;
partTypeFieldSearch.internalId = "896"; //ID of the Part object's "Type" field
partTypeFieldSearch.operatorSpecified = true;
partTypeFieldSearch.searchValue = "Inventory Item"; //only want inventory item parts
//Show me only parts on a certain Order
CustomSearchJoin orderSearchJoin = new CustomSearchJoin();
CustomRecordSearchBasic orderBasicSearch = new CustomRecordSearchBasic();
orderBasicSearch.recType = new RecordRef { internalId = "56" }; //"Order" NetSuite Type ID
//-- WHAT GOES HERE INSTEAD OF SearchStringCustomField?
//adding a search filter on a String Custom Field
SearchStringCustomField fsoItemTypeSearch = new SearchStringCustomField();
fsoItemTypeSearch.#operator = SearchStringFieldOperator.#is;
fsoItemTypeSearch.internalId = "name"; //I have the "name" and numeric "internal id" of the order available.
fsoItemTypeSearch.operatorSpecified = true;
fsoItemTypeSearch.searchValue = order_name;//search filter value
orderSearchJoin.searchRecordBasic = orderBasicSearch;
//add in the things we want to search on
basicRecordSearchParts.customFieldList = new SearchCustomField[] { partTypeFieldSearch };
//add the basic search and join search and then perform the search
searchParts.basic = basicRecordSearchParts;
searchParts.customSearchJoin = new CustomSearchJoin[] { orderSearchJoin };
SearchResult response = netSuiteService.search(searchParts);
return response;
}
I have been trying to solve the syntax for a dynamic linq query that is needed in my application.
I have a dynamic query that the where clause needs to be specified to either
GuidPrimaryKey is contained in a list of Guid OR
GuidPrimaryKey is equal to an item in a list of Guid (using some type of for-loop)
I have a Guid[] populated with over 5,000 keys. My Query is set up as
If I do this (as a test) it is successful
data = data.where("GuidPrimaryKey.Equals(#0)",array[0]);
as well as
data = data.where("GuidPrimaryKey.Equals(#0) OR GuidPrimaryKey.Equals(#1)",array[0], array[1]);
I have tried:data = data.where("GuidPrimaryKey.Contains(#0)",array); but that gives an error: No applicable method 'Contains' exists in type 'Guid'.
I also tried setting a loop to go through the elements in the array and set the where clause as a giant string, but that did not work either.
string s = "";
string p = ""
int counter = 0;
foreach(Guid g in Array)
{
s+= "GuidPrimaryKey.Equals(#" counter.ToString() + ") OR";
p += "Array[" counter.ToString() + "],";
counter++;
}
s = s.remove(s.length - 3, 3);
p = p.remove(p.length - 1, 1);
data = data.Where(s,p);
This gives me the error message: No Property or field '1' exists in type 'DynamicClass1'
Any ideas? I need to have the where clause build the query to check to see if the primary key (GuidPrimaryKey) exists in the list of keys (Guid[]).
I'm not sure if this works in the standard Dynamic Linq library, but I just tried this is my open-source version, and it works well:
var data = data.Where("GuidPrimaryKey in #0", array);
This also works:
var data = data.Where("#0.Contains(GuidPrimaryKey)", array);
Here is a full unit test I wrote to confirm this:
[TestMethod]
public void ExpressionTests_ContainsGuid()
{
//Arrange
//Generate some users with Id fields of type Guid
var userList = User.GenerateSampleModels(5, false);
var userQry = userList.AsQueryable();
//Generate a list of values that will fail.
var failValues = new List<Guid>() {
new Guid("{22222222-7651-4045-962A-3D44DEE71398}"),
new Guid("{33333333-8F80-4497-9125-C96DEE23037D}"),
new Guid("{44444444-E32D-4DE1-8F1C-A144C2B0424D}")
};
//Add a valid Guid so that this list will succeed.
var successValues = failValues.Concat(new[] { userList[0].Id }).ToArray();
//Act
var found1 = userQry.Where("Id in #0", successValues);
var found2 = userQry.Where("#0.Contains(Id)", successValues);
var notFound1 = userQry.Where("Id in #0", failValues);
var notFound2 = userQry.Where("#0.Contains(Id)", failValues);
//Assert
Assert.AreEqual(userList[0].Id, found1.Single().Id);
Assert.AreEqual(userList[0].Id, found2.Single().Id);
Assert.IsFalse(notFound1.Any());
Assert.IsFalse(notFound2.Any());
}