On Sales Orders, when I Copy Order Action. My code error out because the line that retrieves "this._Graph.Caches[BqlCommand.GetItemType(selectorInventoryID)];" is = 0.
The program works fine except on the Action mentioned before.
private Type selectorOrderNbr;
private Type selectorInventoryID;
public ItemDiscountClassAttribute() : base(typeof(ARDiscount.discountID))
{}
protected virtual IEnumerable GetRecords()
{
this.selectorOrderNbr = typeof(SOOrder.orderNbr);
var cache1 = this._Graph.Caches[BqlCommand.GetItemType(selectorOrderNbr)];
var order = (SOOrder)cache1.Current;
this.selectorInventoryID = typeof(SOLine.inventoryID);
var cache2 = this._Graph.Caches[BqlCommand.GetItemType(selectorInventoryID)];
var line = (SOLine)cache2.Current;
should be: cache2 = "{PXCache(1)}"
but output is: cache2 = "{PXCache(0)}"
Highlighted section where var cache2 is 0 and var line is null
Reading through your code, it looks to show the discount applied based on the SOLine. Maybe the issue is discount code is applied before the InventoryID is set on the SOLine? If you update the search for the line to be based on LineNbr, you still may have an empty InventoryID. Maybe returning all discounts when no InventoryID is found may get through the copy operation? If this is the issue, you could reproduce the behavior by selecting a new line, skipping the item, and selecting the discount code first.
Related
I have used FirstOrDefault a ton in my code (its a habit, I used linq2sql a lot in the past) and use it in Acumatica. Per development support, it should only be used when you are expecting one result.
I have some code on SOOrderEntry that gets the item on the current line by clicking a button and checking a few things. This is in my Graph Extension.
This code worked prior to the upgrade:
SOLine Line = Base.Transactions.Current;
InventoryItem Item = SelectFrom<InventoryItem>.Where<InventoryItem.inventoryID.IsEqual<#P.AsInt>>.View.Select(Base, Line.InventoryID).FirstOrDefault();
InventoryItemExt ItemExt = Item.GetExtension<InventoryItemExt>();
The result is not as expected. Line.InventoryID returns 10045, which is the correct item. Item.InventoryID is 10046
After debugging, I found that the new argument that can be used easily is the new property TopFirst. This returns the First Result.
The following code works as expected (and how it worked in 2019 R2 and before!).
SOLine Line = Base.Transactions.Current;
InventoryItem Item = SelectFrom<InventoryItem>.Where<InventoryItem.inventoryID.IsEqual<#P.AsInt>>.View.Select(Base, Line.InventoryID).TopFirst;
InventoryItemExt ItemExt = Item.GetExtension<InventoryItemExt>();
I'm trying to get the line number of a newly inserted INTran row.
Here is the code I'm using:
INRegister issue = new INRegister();
//Code to populate INRegister...
INIssueEntry graph = PXGraph.CreateInstance<INIssueEntry>();
graph.issue.Insert(issue);
graph.Actions.PressSave();
//PXSelect to get new RefNbr for INRegister object
issue = PXSelect<INRegister, Where<INRegister.refNbr, Equal<Current<INRegister.refNbr>>,
And<INRegister.docType, Equal<Current<INRegister.docType>>>>>.Select(graph);
graph.issue.Current = issue;
INTran issueRow = new INTran();
//Code to populate issueRow...
graph.transactions.Insert(issueRow);
graph.transactions.Current = issueRow;
graph.Actions.PressSave();
//Trying to get transaction line number
issueRow = PXSelect<INTran, Where<INTran.refNbr, Equal<Current<INTran.refNbr>>,
And<INTran.docType, Equal<Current<INTran.docType>>,
And<INTran.lineNbr, Equal<Current<INTran.lineNbr>>>>>>.Select(graph);
//At this point, issueRow is now null because LineNbr was null above
row.TranRefNbr = issueRow.RefNbr;
row.TranLineNbr = issueRow.LineNbr;
row.Released = true;
ItemReqs.Update(row);
//... ending code...
I've examined trying to save before setting as current (setting as current item for convenience for when I write the PXSelect to get the LineNbr), but I've found that the LineNbr, even on the graph, stays null during the entire excution. I've looked in the database as the graph is saving the new line and it does contain the line number. I'm not sure why my PXSelect isn't grabbing the line number.
When you insert your transaction row the return should have the linenbr
var issueRow = graph.transactions.Insert(issueRow);
I am guessing your issue is that you are setting current after using the issueRow that was NOT returned which would have a null linenbr.
Also you really do not need to PressSave until the end (or ready to generate the batch) as the linenbr will still get set through the LineNbr attribute. Referring to a save after inserting the INRegister record.
I think current will also be set after you insert so I don't see a need to set current which will remove your need for the PXSelects.
Example getting the LineNbr in the simplest of steps:
INIssueEntry graph = PXGraph.CreateInstance<INIssueEntry>();
graph.issue.Insert(new INRegister());
INTran issueRow = graph.transactions.Insert(new INTran());
//issueRow will now have a LineNbr value...
PXTrace.WriteInformation($"My Line Nbr is {issueRow.LineNbr}");
//RefNbr will receive its value when perform the Persist (Actions.PressSave)
I am new to Coded UI coding so need some help for the below problem I am facing.
I have a WPftable which has the below hierarchy in the UI Map:
this.UICommissionEngineMainWindow.UIXamDataGridCustom.UIRecordsTable
I need to read the cell value from the above table and cells have the below hierarchy:
this.UICommissionEngineMainWindow
.UIXamDataGridCustom
.UIRecordsTable
.UIItemDataItem
.UIItem2443Cell
.UITextBlockText;
When I run the below line of code which has 'GetColumnName' and 'ColumnCount' method it works:
var myrecord = this.UICommissionEngineMainWindow
.UIXamDataGridCustom
.UIRecordsTable.GetColumnNames();
MessageBox.Show(this.UICommissionEngineMainWindow
.UIXamDataGridCustom
.UIRecordsTable
.ColumnCount.ToString());
But when I try to retrieve the cell data it fails. I tried several ways but everytime it fails with
Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException: The playback failed to find the control with the given search properties.
Additional Details:
TechnologyName: 'UIA'
FrameworkId: 'Wpf'
ControlType: 'Cell'
RowIndex: '1'
ColumnIndex: '1'
Search may have failed at 'Records' Table as it may have virtualized children. If the control being searched is descendant of 'Records' Table then including it as the parent container may solve the problem.System.Runtime.InteropServices.COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.
First Try
this.UICommissionEngineMainWindow
.UIXamDataGridCustom
.UIRecordsTable
.GetCell(1, 1)
.Value.ToString());
ALTERNATIVE:
//GetProgramTablehas the Wpftable object in it
var cell = new WpfCell(GetProgramTable());
int row = 1;
int column = 1;
foreach (var data in dataitem.FindMatchingControls())
{
var cell = new WpfCell(data);
cell.SearchProperties.Add(WpfCell.PropertyNames.RowIndex, row.ToString());
cell.SearchProperties.Add(WpfCell.PropertyNames.ColumnIndex, column.ToString());
MessageBox.Show(cell.FindMatchingControls().Count.ToString());
}
ALTERNATIVE:
cell.SearchProperties.Add(WpfCell.PropertyNames.ColumnHeader, "Name");
cell.SearchProperties.Add(WpfCell.PropertyNames.Value, "2143");
MessageBox.Show(cell.FindMatchingControls().Count.ToString())
I am wondering when GetcolumnNames and ColumnCount works why the GetCell doesnt work.
I am creating a custom module in Orchard , I would like to create a query programmatically.
string queryName= "Product";
var item = _orchardServices.ContentManager.New("Query");
item.As<TitlePart>().Title =queryName;
_orchardServices.ContentManager.Create(item, VersionOptions.Draft);
if (!item.Has<IPublishingControlAspect>() && !item.TypeDefinition.Settings.GetModel<ContentTypeSettings>().Draftable)
_orchardServices.ContentManager.Publish(item);
var queryPart = item.As<QueryPart>();
queryPart.ContentItem.ContentType = queryName;
string desc =" filter for the query";
string contentType = "CommonPart.ChannelID.";
var filterGroupRecord = new FilterGroupRecord();
var filterRecord = new FilterRecord()
{
Category = "CommonPartContentFields",
Type = contentType,
Position = 0,
};
filterRecord.State = "<Form><Description>" + desc + "</Description><Operator>Equals</Operator><Value>ChannelId</Value></Form>";
filterGroupRecord.Filters.Add(filterRecord);
queryPart.FilterGroups.Insert(0, filterGroupRecord);
the problem is that:I want set a filters of the query,not a filters group.
could you tell me how to improve my code?
Database structure and class declarations make it impossible. Why do you need it?
Update:
I means that you must use FilterGroupRecord at least one.
But when Query published that Filter Group will be created automatically if query have not yet Filter Group (see at QueryPartHandler). You should add your filters to this group. And not needed to create new group.
var existingFilterGroup = queryPart.FilterGroups[0];
existingFilterGroup.Filters.Add(filterRecord);
Update 2:
To avoid problems with draftable query (and several other potential problems Orchard CMS: Adding default data to fields and then querying them) it is better to move the calling Publish method to the end of your code and other part of your code should be left unchanged. And in your case would be better if you will always publish your query without checking IPublishingControlAspect and Draftable.
I need help creating a LINQ SQL with subsonic. First the basics, this works fine:
var query = (from o in bd.concelhos
orderby o.descricao
select o);
var results = query.ToList<concelhos>();
However, I want to filter out some columns and I have created the following code:
var query = (from o in bd.concelhos
orderby o.descricao
select new FilteredConcelhos { id = o.idDistrito + "/" + o.idConcelho, descricao = o.descricao });
var results = query.ToList<FilteredConcelhos>();
which errors out in the ToList method with the description "Sequence contains no matching element"
Any help would be great with this...
update:
Turns out I was missing get set attributes in the newly declared class...
Like so
public class FilteredConcelhos
{
public string id { get; set; }
public string descricao { get; set; }
}
This clears the exception, but the resulting List is still all wrong (FilteredConcelhos.id contains nothing and FilteredConcelhos.descricao contains numbers)
Can you try to first execute the ToList and the select afterwards - then the select is performed via linq 2 objects!
Have you tried to work with an anonymous type?
var query = (from o in bd.concelhos
orderby o.descricao
select new { id = o.idDistrito + "/" + o.idConcelho,
descricao = o.descricao });
var results = query.ToList();
Unfortunately, this happened to me a lot. I'm not sure about the details of how Linq 2 Object works, but if you'll call ToList on the original object, like this:
from o in bd.concelhos.ToList()
...
It should do the trick.