Selectfrom For Usage In View Select

 

Hello everybody,

I want to leave a short note on how to use SelectFrom for legacy code, and pass it in View.Select for Acumatica newer versions. 

var cmd = new SelectFrom<PartsCatalog>.
    InnerJoin<INSiteStatus>.On<Use<PartsCatalog.inventoryID>.AsInt.IsEqual<Use<INSiteStatus.inventoryID>.AsInt>>.View(this);
 
var s = (currentFilter.PageNbr ?? 0) * (currentFilter.PageSize ?? 0);
int startRow = s > 0 ? s : PXView.StartRow;
int totalRows = 0;
int maxRows = (currentFilter.PageSize ?? 0) == 0 ? PXView.MaximumRows : currentFilter.PageSize ?? 0;
 
var list = cmd.View.Select(new[] { currentFilter }, nullPXView.Searches,
    PXView.SortColumns, PXView.Descendings, PXView.Filters, ref startRowmaxRowsref totalRows).ToList();

As you can see, each time, when field is not converted to a newer Acumatica FBQL, you can refer to Use and AsType.

 

Test Credit Card Numbers

 

Hello everybody,

below goes repost of credit cards numbers, taken from here.

 

Peach Payment Test Cards

Note: Card associations that are available to you depends on the country you do business in, please contact Peach for more information. Please use this guideline, in addition to our online documentation to help with your technical integration.

  • VISA
    • Number: 4012888888881881 or 4111111111111111
    • Expiry: Any future date
    • Verification: 123
    • This 4111111111111111 card simulates 3DSecure in EXTERNAL mode
  •  
  • VISAELECTRON
    • Number: 4012888888881881
    • Expiry: Any future date
    • Verification: 123
  •  
  • MASTER
    • Number: 5105105105105100
    • Expiry: Any future date
    • Verification: 123
  •  
  • DISCOVER
    • Number: 6011587918359498
    • Expiry: Any future date
    • Verification: 123
  •  
  • AMEX
    • Number: 311111111111117
    • Expiry: Any future date
    • Verification: 123
  •  
  • MAESTRO UK
    • Number: 6799851000000032
    • Expiry: Any future date
    • Verification: 123
  •  
  • SOLO
    • Number: 6334580500000000
    • Expiry: Any future date
    • Verification: 123
  •  
  • CARTEBLEUE
    • Number: 4111111111111111
    • Expiry: Any future date
    • Verification: 123

Nedbank Test Cards

  • VISA
    • Number: 4242424242424242
    • Expiry: Any future date
    • Verification: 123
    • Result: Authorised
  •  
  • MASTER
    • Number: 5454545454545454
    • Expiry: Any future date
    • Verification: 123
    • Result: “Unable to Process” or timeout
  •  
  • All other card numbers:
    • "Invalid card number"

Bankserv (3DSecure) Test Cards

  • MASTER
    • Number: 5221266361111726
    • Expiry: 12/2014
    • CVV: 123
    • Password: test123
    • Enrolled Status: N
    • Authentication Status: Y
  •  
  • VISA
    • Number: 4012080132003002
    • Peach System Status: Invalid Card (Error 100.100.101)
  •  
  • VISA
    • Number: 4341793000000034
    • Peach System Status: “Authorized”
  •  
  • VISA
    • Number: 4501155117901011
    • Peach System Status: Invalid Card (Error 100.100.101)
  •  
  • MASTER
    • Number: 5221266361111726
    • Peach System Status: “Authorized”
  •  
  • MASTER
    • Number: 5221008360178290
    • Peach System Status: Invalid Card (Error 100.100.101)
  •  
  • MASTER
    • Number: 5506750000000149
    • Peach System Status: “Authorized”

MasterCard 2 Series BIN Test card numbers

2223 0000 1004 3807
2223 0000 1004 3815
2223 0000 1004 3823
2223 0000 1004 3831

EXPIRY DATE - Any future date
CVV - 123

How To Overrde Authorize Cc Payment Action In Acumatica

 

Hello everybody,

as it was mentioned in one of my previous blog posts, regarding overriding base actions of Acumatica graphs, family of graph extensions grows and grows. 

 

Today I want to share one more code snippet which you can use for extending modification of Acumatica actions. Below goes code fragment, which you can use for modification of Authorize CC Payment:

public class PaymentTransactionExt : PXGraphExtension<PaymentTransactionSOOrderEntry>
{
    [PXOverride]
    public virtual IEnumerable AuthorizeCCPayment(PXAdapter adapterFunc<PXAdapterIEnumerablebaseFunc)
    {
        
        var result = baseFunc(adapter);
        
        return result;
    }
}

Of what I foresee now, is a loooooot of work for Acumatica developers upgrading to a newer versions of Acumatica. 

Why I say so? 

Because as usually ISV have their code in SOOrderEntry extensions. But now they either will need to move their code from SOOrderEntry extensions or for example to reference Base1 ( which is your extension ) as well as Base.

Reason why Acumatica does this is probably following few general programming principles of: SRP ( single responsibility principle ), DRY ( Dont Repeat Yourself ) principle, Open Closed principle on graph level, which in long term will bring more stability to the system.

Basic advice will be this, don't expect that upgrade of your code base to 2019 R2 will be as fast, as it used to be in the past, and before giving estimate which you used to give, pay special attention to how new actions are declared.

 

 

How To Override Shoprates Action In Sales Orders Form

 

Hello everybody,

today I want to leave a short post on how to override Shop rates Action in Acumatica. 

I mean this button:

Below goes C# code, with which you can achieve it:

public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry.CarrierRatesSOOrderEntry>
{
    [PXOverride()]
    public virtual IEnumerable ShopRates(PXAdapter adapterFunc<PXAdapterIEnumerablebaseMethod)
    {
        //your code here
        var retVal = baseMethod?.Invoke(adapter);
        //and possibly here
        return retVal;
    }
}

As you can see from the code, life in Acumatica becomes more complex, and if in the past you've used to override directly your actions, now you'll need to create extension for extension in order to override some Actions. 

Similar issues I've seen in other places of SOOrderEntry, for example in AuthorizeCCPayment, CaptureCCPayment, etc.

 

Pxlongoperation Cleans Everything How To Avoid

 

Hello everybody,

today I want to write a few words about interesting behavior of PXLongOperation.StartOperation in Acumatica.

On the glance that looks pretty simple and straightforward. You have something processing of which will take a long time? Use PXLongOperation.StartOperation. So imagine, you extend ARPaymentEntry graph like this:

public PXAction<ARPayment> StartOperation;
[PXProcessButton]
[PXUIField(DisplayName = "Some long running operation")]
protected virtual IEnumerable startOperation(PXAdapter adapter)
{
   
   PXLongOperation.StartOperation(Base, () => SomeLongRunningOperation(Base.Document.Current));
return adapter.Get(); }

In this case you may notice interesting behavior. If your ARPayment is saved, then everything will work relatively fine. But if not, any kind of data, that user enetered will be lost. How to deal with it. Below goes implementation that will deal with this:

public PXAction<ARPayment> StartOperation;
 
[PXProcessButton]
[PXUIField(DisplayName = "Some long running operation")]
protected virtual IEnumerable startOperation(PXAdapter adapter)
{
    Base.Save.Press();
    PXCache cache = Base.Document.Cache;
    List<ARRegisterlist = new List<ARRegister>();
    list.Add(Base.Document.Current);
    PXLongOperation.StartOperation(Base, () => SomeLongRunningOperation(Base.Document.Current));
    return list;
}

Besides that, in the end of your function SomeLongRunningOperation you may consider adding code like this:

ARPayment arPayment = cuArPayment;
var newGraph = PXGraph.CreateInstance<ARPaymentEntry>();
newGraph.Document.Current =
    Base.Document.Search<ARPayment.refNbr>(arPayment.RefNbr, arPayment.DocType);
 
//  Some additional lines of code
newGraph.Persist();
PXRedirectHelper.TryRedirect(newGraphPXRedirectHelper.WindowMode.Same);

In that case after SomeLongRunningOperation function will finish it's processing, it will refresh current screen of user.

Summary

If you deal with PXLongRunningOperation, you'll need to have following elements:

  1. Save existing item
  2. Return list with one element ( current primary element of view ), which will leave user on the same element
  3. In the end of PXLongRunningOperation call TryRedirect which will refresh currently selected view

 

 

How To Make Dynamic List With Check Boxes In Acumatica

 

Hello everybody,

today I want to share with you a piece of code, with help of which you can get list of all activer order types in Acumatica and also you'll get a chance to select those types with checkbox. Take a look on a screenshot below:

how to achieve this?

Code below without description of DAC class gives you this:

protected virtual void _(Events.FieldSelecting<SetupClassSetupClass.orderTypese)
{
    if (e.Row == null)
    {
        return;
    }
 
    var orderTypes = SelectFrom<SOOrderType>.Where<SOOrderType.active.IsEqual<True>>.View.Select(this).Select(a => a.GetItem<SOOrderType>())
        .ToList();
    var allowedValues = orderTypes.Select(a => a.OrderType).ToArray();
    var allowedLabels = orderTypes.Select(a => a.Descr).ToArray();
 
    var returnState = PXStringState.CreateInstance(e.ReturnValue, allowedLabels.Length, true,
        typeof(SetupClass.orderTypes).Name,
        false, -1, string.Empty, allowedValuesallowedLabelsfalsenull);
    (returnState as PXStringState).MultiSelect = true;
    e.ReturnState = returnState;
}

On aspx level, it look trivial:

<px:PXDropDown ID="PXDropDown1" runat="server" DataField="OrderTypes" CommitChanges="true" />

With help of this code, you'll get list of all order types, which you'll be able to persist in database.

 

How To Insert Varbinary Data In Ms Sql For Acumatica

 

Hello everybody,

sometime it is needed to insert some binary information in one or another table inside of Acumatica. Quite often developers just modify existing record in table UploadFile or UploadFileRevision.

But I don't like such approach, as it is prone to errors and potentially can harm some of your existing data. That's why I propose to use cast operator of MS SQL. Take a look at following example:

insert into UploadFileRevision(CompanyID, FileID, FileRevisionID, Data, Size, CreatedByID, CreatedDateTime, CompanyMask) values
								(2, '35b15ad7-b5c3-4a19-aa77-3a24c046d689', 1, 
													CAST('wahid' AS VARBINARY(MAX)),
													4, 
													'B5344897-037E-4D58-B5C3-1BDFD0F47BF9',
													'2016-06-08 08:53:50.937',
																	0xAA)

 

Take notice of 

CAST('wahid' AS VARBINARY(MAX)),

line. It will insert into local dev instance database varbinary representation of wahid. 

 

Comments Todo And Hack In C

 

Hello everybody,

today I want to leave one more note, which you can use for boosting your productivity.

Imagine following scenario. On the meeting with customer you've got some list of to do points. You have them on your email. You've made some research, and found that you need to make changes to 5 C# files. How not to forget about all of those files?

On rescue comes two comments in C#:

  1. TODO
  2. HACK

Leave those comments in your 5 files -> save all files -> Open Task List, and you'll see something like this:

As you can see from presented screenshot, after you leave TODO or HACK comments in 5 C# files, you'll be in perfect position of usage of code.

What is even more interesting, with help of double click you can navigate to exact comment location.

 

How To Imitate Click On Confirm Shipment In Acumatica

 

Hello everybody,

Today I want to describe how to imiate click on menu item "Confirm shipment" in Acumatica. 

Probably your first guess will be just call method ConfirmShiment of graph SOShipmentEntry. But for now Acumatica team has another advice in order to call this action. Instead of calling method ConfirmShipment you'll need to have a bit more steps.

Code sample below demonstrates those necessary steps:

SOShipmentEntry shipmentGraph = PXGraph.CreateInstance<SOShipmentEntry>(); //Create instance of Graph
PXAutomation.CompleteSimple(shipmentGraph.Document.View);
PXAdapter adapter2 = new PXAdapter(new DummyView(shipmentGraph, shipmentGraph.Document.View.BqlSelect,
						 new List<object> { shipmentGraph.Document.Current }));
adapter2.Menu = SOShipmentEntryActionsAttribute.Messages.ConfirmShipment;
adapter2.Arguments = new Dictionary<stringobject>
{
		{"actionID"SOShipmentEntryActionsAttribute.ConfirmShipment}
};
adapter2.Searches = new object[]{shipmentGraph.Document.Current.ShipmentNbr};
adapter2.SortColumns = new[] { "ShipmentNbr"};
soShipmentGraph.action.PressButton(adapter2);
TimeSpan timespan;
Exception ex;
while (PXLongOperation.GetStatus(shipmentGraph.UID, out timespanout ex) == PXLongRunStatus.InProcess)
{ }
//Here you'll have your shipment confirmed

And DummyView looks like this:

public class DummyView : PXView
    {
        List<object> _Records;
        internal DummyView(PXGraph graphBqlCommand commandList<objectrecords)  : base(graphtruecommand)
        {
            _Records = records;
        }
        public override List<objectSelect(object[] currentsobject[] parametersobject[] searchesstring[] sortcolumns
bool[] descendingsPXFilterRow[] filtersref int startRowint maximumRowsref int totalRows)         {             return _Records;         }     }

If you wonder, why calling ConfirmShipment is not enough, answer is this: ConfirmShipment cal will confirm shipment, but it will not execute Automation Steps. Thats why all of mentioned steps are needed. Otherwise, you'll make long research on question, why something doesn't work in the same way, as it works in UI, but doesn't work from my code.

 

Database Of Acumatica Is In Recovery Pending Condition

 

Hello everybody,

recently I've got interesting situation, when my database for Acumatica developed turned to be in Pending condtion. In order to deal with it, I've executed following SQL:

 

ALTER DATABASE YourDatabase SET EMERGENCY;
GO
ALTER DATABASE YourDatabase set single_user
GO
DBCC CHECKDB (YourDatabase, REPAIR_ALLOW_DATA_LOSS) WITH ALL_ERRORMSGS;
GO
ALTER DATABASE YourDatabase set multi_user
GO

 

and my database turned back to normal.

Update on 10/08/2019

declare @dbName nvarchar(50);
set @dbName = 'yourDatabase';
 
exec( 'ALTER DATABASE' +@dbName  + ' SET EMERGENCY;')
 
exec ('ALTER DATABASE ' + @dbName + '  set single_user')
 
exec ('DBCC CHECKDB (' + @dbName + ' , REPAIR_ALLOW_DATA_LOSS) WITH ALL_ERRORMSGS;')
 
exec ('ALTER DATABASE ' + @dbName +' set multi_user');

I've modified script to a bit another