Question

how to get more than 24 hrs in a PXTimeList Dropdown Field??

  • 15 April 2021
  • 2 replies
  • 31 views

Hi,
I developed new screen. Inside that added one new Field “Labor Time Hrs” which consist of PXTimeList Attribute.
Currently PXTimeList is showing up to 24:00 Hrs.

How to customize that Field to show More than 24 Hrs in a Time dropdown.
Thanks
Giri.


2 replies

Userlevel 6
Badge +3

Hey Giri, I hope you are doing well!

The default TimeList attribute will provide you only 24 Hrs. We need to customize if you want to show more than 24 Hrs.

I just worked on it and please find the customized attribute and screenshot for your reference.

 

In the below example, I’ve added up to 30 hours. If you want to show more than 30 hours you can increase the values in GetValues(30, 60).


 

 

SOOrder Extended DAC 

public class SOOrderExt : PXCacheExtension<SOOrder>
{
[PXDBInt]
[UsrPXTimeListAttribute]
[PXUIField(DisplayName = "Time Span")]
public int? UsrTimeSpan { get; set; }
public abstract class usrTimeSpan : IBqlField{ }

}




Customized Attribute

public class UsrPXTimeListAttribute : PXIntListAttribute
{
public override bool IsLocalizable
{
get
{
return false;
}
}

public UsrPXTimeListAttribute()
: base(UsrPXTimeListAttribute.GetValues(30, 60), UsrPXTimeListAttribute.GetLabels(UsrPXTimeListAttribute.GetValues(30, 60)))
{
}

public UsrPXTimeListAttribute(int step, int count)
: base(UsrPXTimeListAttribute.GetValues(step, count), UsrPXTimeListAttribute.GetLabels(UsrPXTimeListAttribute.GetValues(step, count)))
{
}

public override void CacheAttached(PXCache sender)
{
base.CacheAttached(sender);
sender.Graph.FieldUpdating.AddHandler(sender.GetItemType(), base._FieldName, this.FieldUpdating);
}

public override void FieldSelecting(PXCache sender, PXFieldSelectingEventArgs e)
{
base.FieldSelecting(sender, e);
PXIntState V_8 = e.ReturnState as PXIntState;
if (V_8 != null)
{
int[] V_10 = V_8.AllowedValues;
string[] V_9 = V_8.AllowedLabels;
if (V_8.Required.HasValue)
{
bool? V_7 = V_8.Required;
bool V_6 = true;
bool flag = V_7.GetValueOrDefault() == V_6 & V_7.HasValue;
}
if (e.ReturnValue != null)
{
int V_5 = (int)e.ReturnValue;
if (V_10 != null && !V_10.Contains(V_5))
{
V_10 = V_10.Append(V_5).ToArray();
V_9 = V_9.Append(UsrPXTimeListAttribute.GetString(V_5)).ToArray();
}
}
e.ReturnState = PXTimeState.CreateInstance(V_8, V_10, V_9);
}
}

protected void FieldUpdating(PXCache sender, PXFieldUpdatingEventArgs e)
{
if (!sender.Graph.IsImportFromExcel && !sender.Graph.IsImport)
{
return;
}
if (!(e.NewValue is int) && !string.IsNullOrEmpty((string)e.NewValue))
{
string V_0 = e.NewValue as string;
if (V_0 != null && !new Regex("^[0-9]+$", RegexOptions.Compiled | RegexOptions.Singleline).IsMatch(V_0))
{
TimeSpan V_ = default(TimeSpan);
if (!TimeSpan.TryParse(V_0, out V_))
{
throw new PXException("\"{0}\" cannot be converted to Time.", e.NewValue);
}
e.NewValue = (int)V_.TotalMinutes;
}
}
}

public static int[] GetValues(int step, int count)
{
List<int> V_2 = new List<int>(100);
for (int V_ = 0; V_ <= count; V_++)
{
V_2.Add(V_ * step);
}
return V_2.ToArray();
}

public static string[] GetLabels(int[] values)
{
List<string> V_5 = new List<string>();
foreach (int V_3 in values)
{
V_5.Add(UsrPXTimeListAttribute.GetString(V_3));
}
return V_5.ToArray();
}

public static string GetString(int totalMinutes)
{
TimeSpan V_0 = TimeSpan.FromMinutes((double)Math.Abs(totalMinutes));
if (totalMinutes < 0)
{
return string.Format("-{0:d2}:{1:d2}", (int)Math.Truncate(V_0.TotalHours), V_0.Minutes);
}
return string.Format("{0:d2}:{1:d2}", (int)Math.Truncate(V_0.TotalHours), V_0.Minutes);
}
}


 

Thanks Naveen.

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 — 2020  Acumatica, Inc. All rights reserved