How to mark a given number as used in a NumberSequence when this number was not generated by the number sequence?
Let's consider I imported the first 10 records of a custom table and the file already specified its ID from 01 to 10,
then i want to intercept insert() mark the given number as used so that after importing, the first manually created record will assign ID 11.
This would be something like updating the field 'Next' in the NumberSequence.
Update the NumberSequenceTable.NextRec value to the desired value.
Make sure that format is correct.
Example code:
NumberSequenceTable numberSequenceTable;
ttsBegin;
select forUpdate numberSequenceTable
where numberSequenceTable.NumberSequence == 'Acco_1' // as example
;
numberSequenceTable.NextRec = 11;
if (numberSequenceTable.validateField(fieldNum(NumberSequenceTable, NextRec))
&& numberSequenceTable.validateWrite()
)
{
numberSequenceTable.update();
}
else
{
throw error("Validation failed");
}
ttsCommit;
Related
I want to set a default value based on curUserid() in PurchCreateOrder. How can I put data in my field on form extension ?
Is there any better option of doing this ? Fields are bound to datasource and I have different fields with differentdatasources.
My code is giving me abnormal termination error with nullreferences. XPPCompiler
[ExtensionOf(tableStr(PurchTable))]
final class PurchCreateOrderGetDefAdress_Extension
{
void initvalue(PurchaseType _purchaseType)
{
next initvalue(_purchaseType);
PurchTable purchtable;
LogisticsPostalAddress logpostadress;
UserInfoSz usrsz;
str user = curUserId();
select firstonly logpostadress where logpostadress.city == 'lub';
// select firstonly InventSiteId, InventLocationId from purchtable join usrsz where purchtable.InventSiteId == usrsz.InventSiteId && usrsz.IsDefault == true;
select firstonly InventSiteId from usrsz where usrsz.UserId == user && usrsz.IsDefault == true;
purchtable.initValue();
purchtable.deliveryname = 'asasasasas' ;//logpostadress.Address;
purchtable.inventsiteid = usrsz.InventSiteId;
purchtable.inventlocationid = usrsz.InventSiteId;
info(strFmt("%1, %2, %3", logpostadress.Address, usrsz.InventSiteId));
}
}
The error is straight forward.
Error The augmented class 'PurchTable' provides a method by this name, but this method cannot be used as a chain of command method since the parameter profile does not match the original method.
Take a look at the highlighted parameter profile and compare to yours.
Edit: Take a look at these links for more info on Chain of Command (CoC):
https://learn.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/extensibility/method-wrapping-coc
https://channel9.msdn.com/Blogs/mfp/X-Chain-Of-Command (This video is excellent)
I would like to retrieve the userInfoId from the database and pass it into var where the Login username is Kenny. However, the value returned to u was 0 instead of the desired value. I have tried selecting another username but the result was still the same.
var u = Database.UserInfo
.Where(userinfo => userinfo.LoginUserName == "BEN")
.Select(x=> x.UserInfoId)
.FirstOrDefault();
Put some breakpoints and see what you have inside u, Use the query below and you should be good to go. Make sure the table/column names are correct according to your db.
int userInfoId = (from x in context.UserInfo
where x.LoginUserName == "Kenny"
select x.UserInfoId).SingleOrDefault());
if (userInfoId > 0){
// user exists and do what you wish to next
}
else {
// user does not exist
}
I am using QtableView(qt5.9) with 10 columns and want to disable sorting for 2nd and 3rd (only some) columns when the user clicks on the header of these columns.
I use setsortingenabled flag to make my QtableView allow sorting
Is there any signal which I should listen to on clicking of header and then call some appropraite method or deny sorting.
You can use the header signal sortIndicatorChanged to restore the current sort indicator.
Example:
connect(m_poTableView->header(), &QHeaderView::sortIndicatorChanged,
this, &MyClass::HandleIndicatorChanged);
MyClass::HandleIndicatorChanged(int logicalIndex, Qt::SortOrder eSort)
{
if (logicalIndex != 0)
{
this->m_poTableView->horizontalHeader()->setSortIndicator(
0, this->m_poTableView->model()->sortOrder());
}
}
An easier way (for me, at least) is to subclass the filter proxy and override sorting for just the disabled columns. The below code is in Python, but it is a simple translation to C++.
def CustomSorter(QtCor.QSortFilterProxyModel):
def sort(self, column: int, order: QtCore.Qt.SortOrder) -> None:
if column == 2 or column == 3:
# Do nothing instead of sorting
return
else:
# Sort as usual
super().sort(column, order)
This is the code I use in the case I only want to allow sorting column 2 (sOrder is a private int member of MyClass):
connect(ui->tableView->horizontalHeader(), &QHeaderView::sortIndicatorChanged, this, &MyClass::onSortIndicatorChanged);
void MyClass::onSortIndicatorChanged(int column, Qt::SortOrder order)
{
if (column == 2){
// Record the sort order when it is column 2
sOrder = order;
}
else{
// Restore the column 2 sort order
ui->tableView->sortByColumn(2, sOrder);
}
}
I have some json, for examle:
data = {
"name":"Bob","age":"20",
"name":"Jo","age":"21",
"name":"Jo","age":"22",
"name":"Nick","age":"23"
}
Next, I use crossfilter, create dimension and filter it:
let ndx = crossfilter(data);
let dim = ndx.dimension(d => d.name).filter(d !== "Jo");
//try to get filtered values
let filtered = dim.top(Infinity); // -> return 2 values where 'name'!='Jo'
//"name":"Bob","age":"20"
//"name":"Nick","age":"23"
let myGroup = dim.group(d => {
if(d === 'Jo') {
//Why we come here? This values must be filtered already
}
})
How can I filter my dimension and don't have these values on 'dim.group'?
Not sure what version you are using, but in the current version of Crossfilter, when a new group is created all records are first added to the group and then filtered records are removed. So the group accessor will be run at least once for all records.
Why do we do this? Because for certain types of grouping logic, it is important for the group to "see" a full picture of all records that are in scope.
It is possible that the group accessor is run over all records (even filtered ones) anyway in order to build the group index, but I don't remember.
I have a method for a display field which does the following;
return InventSum::find(_salesLine.ItemId, InventDim::_salesLine.InventDimId).AvailPhysical();
This gives me the on-hand Available Physical for the line site/warehouse/location.
I need to see the total available for just the site/warehouse. I think I need to search inventDim by Item/Warehouse to get my inventdimid, but I cannot find the method so I am suspicious that this is incorrect.
Can anyone help?
My working solution...
InventDimParm invDimParm;
InventDim warehouseInvDim;
InventDim salesLineInventDim;
;
salesLineInventDim = _salesLine.inventDim();
warehouseInvDim.InventSiteId = salesLineInventDim.InventSiteId;
warehouseInvDim.InventLocationId = salesLineInventDim.InventLocationId;
warehouseInvDim = InventDim::findOrCreate(warehouseInvDim);
invDimParm.initFromInventDim(InventDim::find(warehouseInvDim.inventDimId));
return InventSum::findSum(_salesLine.ItemId,warehouseInvDim,invDimParm).availOrdered();
I know this is for availOrdered() but it works exactly the same for availPhysical()
You should use the InventOnhand class.
It sums the invent on-hand values based on criteria like item id and inventory dimensions.
There are lots of uses in AX, search the Class node.
The following job finds all Sales Lines with the Open Order status, which have an Available Physical quantity on hand matching all dimensions specified on the Sales Lines except location:
static void FindOpenSalesLineAvailPhys(Args _args)
{
SalesLine salesline;
InventDim inventDim;
InventDimParm inventDimParm;
InventOnHand inventOnHand;
;
while select salesLine where salesLine.SalesStatus == SalesStatus::Backorder
{
inventDim = salesLine.inventDim();
inventDimParm.initFromInventDim(inventDim);
inventDimParm.WMSLocationIdFlag = NoYes::No;
inventOnHand = InventOnHand::newItemDim(salesLine.ItemId, inventDim, inventDimParm);
if (inventOnHand.availPhysical())
{
info(strfmt("Sales Order %1 Line %2 Item Id %3 Available Physical (ignoring Location) %4",
salesLine.salesId, salesLine.LineNum, salesLine.ItemId, inventOnHand.availPhysical()));
}
}
}
You basically set your inventDim values the way you want to search for them, and then do an InventDim::FindOrCreate to see if either the inventory dimension already exists, or it needs to be created and a new number sequence will be consumed. This is used so that the InventDim table doesn't store every single possible combination of dimensions. Also because if you have any serialized products, it's not feasible for the table to store all of the combinations, so it only stores the ones it needs.
InventDim inventDim;
SalesLine _salesLine;
;
inventDim.InventSiteId = 'mySite';
inventDim.InventLocationId = 'myWarehouse';
inventDim = InventDim::findOrCreate(inventDim);
return InventSum::find(_salesLine.ItemId, inventDim.inventDimId).AvailPhysical();