Three States Of Fields In Acumatica

 

Hello everybody,

today I want to write a short note on three states of fields existing in Acumatica:

  1. Exists but is empty
  2. Exist and have value
  3. Has null

If to speak about string, it can exist like this:

  1.  
  2. Some value
  3.  

Do you see difference between 1 and 3? Not easy. As usually developers of C#, show this difference like this:

  1. ""
  2. "Some Value"
  3. null

And following screenshot with explanation shows how it works in case of SOAP contracts:

 so, while you make integration, keep that in mind

New Functions For Redirect In Acumatica

 

Hello everybody,

today I want to say few words about new functions for redirect in Acumatica, and particularly about class PXRedirectHelper. 

Classical approach from T200/T300 manual may look like this:

var currentCse = Cases.Current;
if(currentCse == null)
	return;
 
 
var graph = PXGraph.CreateInstance<CRCaseMaint>();
graph.Case.Current = graph.Case.Search<CRCase.caseCD>(currentCse.CaseCD);
if (graph.Case.Current != null)
{
	throw new PXRedirectRequiredException(graphtrue"Case details");
}

But with new function all of those lines can be simplified to this:

PXRedirectHelper.TryRedirect(Cases.Cache, Cases.Current, "Edit case"PXRedirectHelper.WindowMode.NewWindow);

With that approach you'll get the same result, but just in one line of code. 

Simplest Caching Explanation

Hello everybody,

today I want to give one more explanation of how to use caching and slots for caching purposes. Also there are plenty of articles on the subject,  I want to give one more with simplest recipe. So, if you need to cache something, you'll need to follow this procedure:

  1. declare you class as something that inherits IPrefetchable
  2. Create some placeholder in your class for storing items in the cache
  3. Implement Prefetch
  4. Implement GetSlot

 

Take a look on the code below, how it can be done:

public class ArTranFetcher : IPrefetchable
{
	private List<ARTran> _arTranList = new List<ARTran>();
 
	public void Prefetch()
	{
		_configurableList = new List<ARTran>();
 
		var dbRecords = PXDatabase.Select<ARTran>();
		foreach (var csAttributeDetailConfigurable in dbRecords)
		{
			_arTranList.Add(csAttributeDetailConfigurable);
		}
	}
 
	public static List<ARTran> GetARTrans()
	{
		var def = GetSlot();
		return def._arTranList;
	}
		
	private static ArTranFetcher GetSlot()
	{
		return PXDatabase.GetSlot<ArTranFetcher>("ARtranFetcherSlot"typeof(ARTran));
	}
 
}

 

few more explanations on presented code.

  1. Placeholder will be _arTranList 
  2. GetSlot will be monitoring database ARTran ( because of typeof(ARTran) statement ). So each time ARTRan will be updated, GetSlot will be executed automatically via framework.
  3. In your code you can get cached valus via following line of code: var arTrans = ArTranFetcher.GetARTrans();

 

with usage of such tricks, you can optimize plenty of staff. The only warning would be don't cache ARTran, as it will swallow up all memory of your server.

 

 

Acumatica Page Missing Under Google Chrome Browser

 

Hello everybody,

This one is a hot topic, recently chrome team released some changes to the Chrome Browser, so that some PAGES could get missing.

You still see Menu, still see screen list but the page itself is gone, blank, empty.

How to fix?

Just change settings in the Chrome:

1. Type chrome://flags/ in the browser address bar and press Enter.

2. You should see the list of options:

3. In the search bar type Lazy Frame or just Lazy:

4. Under Enable lazy frame loading choose Disabled:

5. Press Relaunch Now at the right bottom corner:

 

 

How To Modify Activities Behavior On Business Accounts Page

Hello everybody,

today I want to write a few words on how to modify behavior of buttons Add task, Add event, Add email, Add activity, ..., Add work item of Business Accounts page.

The main issue of chaning it is in the fact, that it is not just ordinary buttons, but separate class, which has injection of logic. Part of it's declaration goes below:

public class CRActivityList<TPrimaryView> : CRActivityListBase<TPrimaryView, CRPMTimeActivity>
  where TPrimaryView : class, IBqlTable, new()
{
  public CRActivityList(PXGraph graph)
    : base(graph)
  {
  }
 
  public CRActivityList(PXGraph graphDelegate handler)
    : base(graphhandler)
  {
  }
}

To my surprise, in order to override it's behavior you'll need to inherit from CRActivityList, and add your logic, for example like this:

public class BusinessAccountMaintExt : PXGraphExtension<BusinessAccountMaint>
{
	[PXViewName(Messages.Activities)]
	[PXFilterable]
	[CRReference(typeof(BAccount.bAccountID), Persistent = true)]
	public CRActivityListModified<BAccount> Activities;
}
 
public class CRActivityListModified<TPrimaryView> : CRActivityList<TPrimaryView>
	where TPrimaryView : classIBqlTablenew()
{
	public CRActivityListModified(PXGraph graph)
		: base(graph)
	{
	}
 
	public CRActivityListModified(PXGraph graphDelegate handler)
		: base(graphhandler)
	{
	}
 
	public override IEnumerable NewTask(PXAdapter adapter)
	{
		try
		{
			base.NewTask(adapter);  // throws exception, catch it and add you needed logic
		}
		catch (PXRedirectRequiredException ex)
		{
			var g = (CRTaskMaint)ex.Graph;
			var a = g.Tasks.Current;
			a.Subject = "Test Subject";
			a = g.Tasks.Update(a);
 
			var timeactivity = g.TimeActivity.Current;
 
			throw;
		}
 
		return adapter.Get();
	}
 
	public override IEnumerable NewEvent(PXAdapter adapter)
	{
		try
		{
			base.NewEvent(adapter);
		}
		catch (PXRedirectRequiredException ex)
		{
			var g = (EPEventMaint)ex.Graph;
			var a = g.Events.Current;
			a.Subject = "Test Subject";
			a = g.Events.Update(a);
 
			var timeactivity = g.TimeActivity.Current;
 
			throw;
		}
 
		return adapter.Get();
	}
 
	public override IEnumerable NewMailActivity(PXAdapter adapter)
	{
		try
		{
			base.NewMailActivity(adapter);
		}
		catch (PXRedirectRequiredException ex)
		{
			var g = (CREmailActivityMaint)ex.Graph;
			var a = g.Message.Current;
			a.Subject = "Test Subject";
			a = g.Message.Update(a);
 
			var timeactivity = g.TimeActivity.Current;
 
			throw;
		}
 
		return adapter.Get();
	}
 
	public override IEnumerable NewActivity(PXAdapter adapter)
	{
		return base.NewActivity(adapter);
	}
 
	protected override IEnumerable NewActivityByType(PXAdapter adapterstring type)
	{
		try
		{
			base.NewActivityByType(adaptertype);
		}
		catch (PXRedirectRequiredException ex)
		{
			var g = (CRActivityMaint)ex.Graph;
			var a = g.Activities.Current;
			a.Subject = "Test Subject";
			a = g.Activities.Update(a);
 
			var timeactivity = g.TimeActivity.Current;
 
			throw;
		}
 
		return adapter.Get();
	}
}

Few comments to presented code.

  1. All pop ups appear after exception, so you'll not be able to avoid exceptions, no matter what
  2. Your addendums should be modified in catch
  3. throw; will re-throw exception one more time. This is particularly interesitng detail, which you can re-use in some other scenarios when you need to deal with pop ups

Summary

Acumatica is very flexible, and the base flexibility mechanism is inheritance and polymorphism, two pillars of OOP.  In case if you need to change behavior of Cases screen, you'll need to inherit-override CRPMTimeActivity class.

How to modify PXIntList dynamically in Acumatica

Hello everybody,

today I want to leave a short code sample on how to modify PXIntList or dropdown list in Acumatica. Below goes code sample of it:

protected virtual void _(Events.RowSelected<CROpportunity> e)
{
    if (e.Row == null)
        return;
    var opportunityExtension = e.Row.GetExtension<CROpportunityExt>();
 
    if (opportunityExtension.UsrProduct == 0)
    {
        var listInts = new List<int>();
        var listStrings = new List<String>();
 
        listInts.Add(0);
        listInts.Add(1);
        listInts.Add(2);
 
        listStrings.Add("String 1");
        listStrings.Add("String 2");
        listStrings.Add("String 3");
 
        PXIntListAttribute.SetList<CROpportunityExt.usrProposition>(e.Cache, e.Row, listInts.ToArray(), listStrings.ToArray());
    }
 
    if (opportunityExtension.UsrProduct == 1)
    {
        var listInts = new List<int>();
        var listStrings = new List<String>();
 
        listInts.Add(0);
        listInts.Add(3);
        listInts.Add(5);
 
        listStrings.Add("String 2");
        listStrings.Add("String 3");
        listStrings.Add("String 4");
 
        PXIntListAttribute.SetList<CROpportunityExt.usrProposition>(e.Cache, e.Row, listInts.ToArray(), listStrings.ToArray());
    }
}

This code sample has two most important parts: 

  1. RowSelected ( declared over new syntax )
  2. PXIntListAttribute.SetList<CROpportunityExt.usrProposition> call

With usage of those two principles you can easily get modifiable collection accoding to necessary conditions in your code.

 

Fbql Brackets

FBQL brackets

Hello everybody,

today I want to speak about one very interesting feature of FBQL, which I don't know if exists in BQL. Function Brackets!

Take a look on following code sample:

var bracketsDemo = SelectFrom<SOOrder>.InnerJoin<SOLine>.On<SOLine.orderNbr.IsEqual<SOOrder.orderNbr>>.InnerJoin<SOShipLine>
	.On<SOShipLine.origOrderNbr.IsEqual<SOOrder.orderNbr>>.Where<
		Brackets<SOShipLine.confirmed.IsNotNull.
			And<SOShipLine.baseOrigOrderQty.IsNotNull>.
			And<SOShipLine.completeQtyMin.IsNotNull>.
			And<SOShipLine.confirmed.IsEqual<True>.
				Or<SOShipLine.confirmed.IsNull>>.
			And<SOShipLine.baseOriginalShippedQty.IsGreater<SOShipLine.unassignedQty>.
				Or<SOShipLine.baseOrigOrderQty.IsLess<SOShipLine.baseOriginalShippedQty>>>>.
		Or<SOShipLine.baseOrigOrderQty.IsNotNull>>.AggregateTo<GroupBy<SOOrder.orderNbr>,
		Min<SOOrder.curyDiscTot>>.OrderBy<SOOrder.curyFreightAmt.AscSOOrder.curyDocDisc.Desc>.View.Select(Base);

as you can see from the code, now in FBQL if you need to have Or operator, then as anohter option you may use Brackets.

How To Pass Data Into Processing Method With Help Of Lambda Expression

How to pass data into processing method with help of lambda expression

Hello everybody,

today I want to leave a short note on how to pass some additional parameters into Processing method of processing page with help of lambda expression. Syntax is pretty simple:

public class SSShipmentDateResetter : PXGraph<SSShipmentDateResetter>
{
	public PXFilter<ShipmentFilter> ShipmentFilter;
 
	public PXFilteredProcessing<SOShipment, ShipmentFilter> ShipmentsForProcessing;
 
	public SSShipmentDateResetter()
	{
		var shipmentFilter = ShipmentFilter.Current;
		ShipmentsForProcessing.SetProcessDelegate(shipments =>
		{
			ResetDate(shipmentFilter, shipments);
		});
	}
 
	public static void ResetDate(ShipmentFilter filter,  List<SOShipment> shipments)
	{
		
	}
}

for me such approach is a bit easier to use as it involes a bit less amout of typing.

If you want to have even simpler syntax, then following sample also may work for you:

public SSShipmentDateResetter()
{
	var filter = ShipmentFilter.Current;
	ShipmentsForProcessing.SetProcessDelegate(shipments => ResetDate(filter, shipments));
}

For simplicity sake, I've showed only constructor.

 

 

How To Restore Snapshot Of Acumatica

Hello everybody,

today I want to leave a post on how to restore Acumatica snapshots with help of Acumatica Wizard.

Before creating snapshot you may need to switch Acumatica to maintenance mode. Below are the steps for achieveing it:

1. Go to System --> Management --> Apply Updates, click on the button "Schedule Lockout" and specify the reason for lockout
2. Don't forget to remove the lockout after you'll restore Snapshot.

Steps are the following:

1. Create a snapshot of the tenant you wish to back up

2. Export that snapshot (I recoment  xml format).

3. In the folder where the corresponding Acumatica Wizard is installed (usually c:\program files\Acumatica ERP\), find the folder called  \Database\Data, where there are individual folders with snapshot data.

4. Create a new folder for your new snapshot

5. Extract the contents of the .zip exported snapshot into the new folder you created

6. Run the Acumatica Wizard

7. Choose the "Perform Application Maintenance" option

8. Select the site into which you wish to import this data

9. Choose the "Tenant Maintenance" option or "Company Maintenance":

10. Click on the "Advanced Settings" button at the bottom

12. Click on the "Insert Data" option next to the tenant where the data should be imported and select the new folder/snapshot you added in step #4 above:

13. Proceed through the wizard as normal. When the install process is complete you should have a tenant with restored data.

 

New Syntax Of Setvisibility Method In Acumatica

 

Hello everybody,

today I want to write a few words about changes of PXUIFieldAttribute.SetVisibility method. 

In the past, if you wanted to turn on some column, you could write in RowSelected event something like this:

          PXUIFieldAttribute.SetVisibility<APRegister.finPeriodID>(Documents.Cache, nulltrue);

If you want to turn it off, then this:

PXUIFieldAttribute.SetVisibility<APRegister.finPeriodID>(Documents.Cache, nullfalse);

But for quite a long time ( even in 2017 version ), Acumatica team introduced PXUIVisibility enum. In code it looks like this:

[Flags]
public enum PXUIVisibility
{
  Undefined = 0,
  Invisible = 1,
  Visible = 3,
  SelectorVisible = 7,
  Dynamic = 9,
  Service = 19,
  HiddenByAccessRights = 33,
}

For now I can comment on Visible and InVisible which correspond to false and true in the past implemtations. And in future posts I'll describe other selectors.