Solved

Dynamically changing Warehouse Selector in Acumatica

  • 1 October 2021
  • 3 replies
  • 122 views

I want to dynamically change the warehouse selector results in Acumatica on the following screens:

  • Opportunities
  • Sales Orders
  • Purchase orders
  • Sales Quotes
  • Requisitions

, by either company(All warehouse under selected company) or branch. The condition will be met with custom fields I have added to the Inventory preferences screen.

I came to the conclusion of having to use a custom selector attribute, but how to achieve this I am not sure.

Any guidance and help would be greatly appreciated.

See code attached for my Custom DAC fields and the code for the Sales Order Graph:

public class INSetupExt : PXCacheExtension<PX.Objects.IN.INSetup>
{
#region UsrAllowBlockin
[PXDBBool]
[PXDefault(false)]
[PXUIField(DisplayName="Block Normal Journal Posting by Creator")]

public virtual bool? UsrAllowBlockin { get; set; }
public abstract class usrAllowBlockin : PX.Data.BQL.BqlBool.Field<usrAllowBlockin> { }
#endregion

#region UsrByCompany
[PXDBBool]
[PXDefault(true)]
[PXUIField(DisplayName="By Company")]
[PXUIEnabled(typeof(Where<usrAllowBlockin, NotEqual<False>>))]
[PXUIVisible(typeof(Where<usrAllowBlockin, NotEqual<False>>))]

public virtual bool? UsrByCompany { get; set; }
public abstract class usrByCompany : PX.Data.BQL.BqlBool.Field<usrByCompany> { }
#endregion

#region UsrByBranch
[PXDBBool]
[PXDefault(false)]
[PXUIField(DisplayName="By Branch")]
[PXUIEnabled(typeof(Where<usrAllowBlockin, NotEqual<False>>))]
[PXUIVisible(typeof(Where<usrAllowBlockin, NotEqual<False>>))]

public virtual bool? UsrByBranch { get; set; }
public abstract class usrByBranch : PX.Data.BQL.BqlBool.Field<usrByBranch> { }
#endregion
}
protected void SOLine_BranchID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated InvokeBaseHandler)
{
if (InvokeBaseHandler != null)
InvokeBaseHandler(cache, e);
var row = (SOLine)e.Row;

INSetupExt extINSetup = Base.insetup.SelectSingle().GetExtension<INSetupExt>();


if (row != null)
{
//retrieve current branch
int? currentSelectedBranch = Base.Document.Current?.BranchID;

//See what condition is selected
//If filter by branch is selected, based on the branch selected in the financial tab,
//allow selection of all warehouses linked the transaction branch only
//Else if filter by company is selected,
//allow selection of all warehouses linked to the company or branches within the company associated with the document branch.

if (extINSetup.UsrAllowBlockin == true && extINSetup.UsrByBranch == true)
{

}
else if (extINSetup.UsrAllowBlockin == true && extINSetup.UsrByCompany == true)
{

}
}
}

 

icon

Best answer by Naveen Boga 1 October 2021, 13:52

View original

3 replies

Userlevel 7
Badge +12

Hi @charlbester34  This can be achieved though the custom selector for the Warehouse ID at SOLine level.

I worked on the Custom Selector for the Order Type field in the Custom screen. Sharing the code here for your reference. Hope this helps!

//Custom DAC Order Type Field 

public class MyCustomDAC : IBqlTable
{

#region OrderType

[PXDBString(2, IsFixed = true, IsUnicode = false, InputMask = ">aa")]
[PXDefault()]
[PXUIField(DisplayName = "Order Type")]
[OrderTypeSelector(typeof(SOOrderType.orderType), IsDirty = false)]
public virtual string OrderType { get; set; }
public abstract class orderType : IBqlField { }

#endregion
}

// CustomSelector Attribute code

[Serializable]
public class OrderTypeSelector : PXCustomSelectorAttribute
{
public OrderTypeSelector(Type type)
: base(type, typeof(SOOrderType.orderType), typeof(SOOrderType.descr), typeof(SOOrderType.template), typeof(SOOrderType.behavior))
{
}
public virtual IEnumerable GetRecords()
{
MyCustomDAC currentItem = (MyCustomDAC)this._Graph.Views["setupConfigview"].Cache.Current;
if (currentItem == null) return null;

PXSelectBase<SOOrderType> ordertype = new PXSelectJoin<SOOrderType, InnerJoin<SOOrderTypeOperation, On<SOOrderTypeOperation.orderType,
Equal<SOOrderType.orderType>, And<SOOrderTypeOperation.operation, Equal<SOOrderType.defaultOperation>>>>>(this._Graph);

switch (currentItem.IntegrationType.Trim())
{
case SOConstants.Condition 1:
case SOConstants.Condition 2:
case SOConstants.Condition 3:
case SOConstants.Condition 4:
case SOConstants.Condition 5:
case SOConstants.Condition 6:
ordertype.WhereAnd<Where<SOOrderType.template, Equal<SOConstants.InvoiceType>>>();
return ordertype.Select();
case SOConstants.Condition 7:
ordertype.WhereAnd<Where<SOOrderType.template, Equal<SOConstants.SalesOrderType>>>();
return ordertype.Select();
}
return null;
}
}

 

Hi @Naveen B,


If I am understanding this correctly, I will need to create a new custom graph and DAC extension of the SOLine DAC through the customization project editor under the code tab, and change the properties under the DAC Warehouse field to point to my custom selector where I am writing the logic in the new graph.
 

Userlevel 7
Badge +12

No @charlbester34  Since you wanted to have custom selector for the SOLine level field.

Please write a cache attached code for the SOLine Warehouse field and invoke the customselector. 

Please find the sample code below.

 

 [PXMergeAttributes(Method = MergeMethod.Merge)]
[NEWCustomSelector(typeof(INSite.siteID))]
protected virtual void SOLine_SiteID_CacheAttached(PXCache cache)
{
}


[Serializable]
public class NEWCustomSelector : PXCustomSelectorAttribute
{
public NEWCustomSelector(Type type)
: base(type, typeof(INSite.SiteID), typeof(INSite.Descr))
{
}
public virtual IEnumerable GetRecords()
{
SOLine currentItem = (SOLine)this._Graph.Views["Transactions"].Cache.Current;
if (currentItem == null) return null;

// Add Logic
}
}

 

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2022  Acumatica, Inc. All rights reserved