Skip to main content

Hi, I have a user defined field in customer screen (LocationExt.usrExpectedPaymentDate) as below,

 

I need to access this field for a calculation in the sales order entry graph but I get this error.

>2024-10-23 04:45:10.957] \App_Code\Caches\SOOrderEntry.cs(159): error CS0246: The type or namespace name 'StandaloneLocationExt' could not be found (are you missing a using directive or an assembly reference?)
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using PX.Common;
using PX.Data;
using PX.Objects.AP;
using PX.Objects.AR;
using PX.Objects.CA;
using PX.Objects.CM;
using PX.Objects.CR;
using PX.Objects.CS;
using PX.Objects.DR;
using PX.Objects.EP;
using PX.Objects.GL;
using PX.Objects.IN;
using PX.Objects.PM;
using PX.Objects.PO;
using PX.Objects.TX;
using POLine = PX.Objects.PO.POLine;
using POOrder = PX.Objects.PO.POOrder;
using PX.CarrierService;
using PX.Concurrency;
using CRLocation = PX.Objects.CR.Standalone.Location;
using PX.Objects.AR.CCPaymentProcessing;
using PX.Objects.AR.CCPaymentProcessing.Common;
using PX.Objects.AR.CCPaymentProcessing.Helpers;
using PX.Objects.AR.CCPaymentProcessing.Interfaces;
using ARRegisterAlias = PX.Objects.AR.Standalone.ARRegisterAlias;
using PX.Objects.AR.MigrationMode;
using PX.Objects.Common;
using PX.Objects.Common.Discount;
using PX.Objects.Common.Extensions;
using PX.Objects.IN.Overrides.INDocumentRelease;
using PX.CS.Contracts.Interfaces;
using Message = PX.CarrierService.Message;
using PX.TaxProvider;
using PX.Data.DependencyInjection;
using PX.Data.WorkflowAPI;
using PX.LicensePolicy;
using PX.Objects.Extensions.PaymentTransaction;
using PX.Objects.SO.GraphExtensions.CarrierRates;
using PX.Objects.SO.GraphExtensions.SOOrderEntryExt;
using PX.Objects.SO.Attributes;
using PX.Objects.Common.Attributes;
using PX.Objects.Common.Bql;
using OrderActions = PX.Objects.SO.SOOrderEntryActionsAttribute;
using PX.Objects.SO.DAC.Projections;
using PX.Data.BQL.Fluent;
using PX.Data.Localization;
using PX.Data.Reports;
using PX.Objects.IN.DAC.Accumulators;
using PX.Data.BQL;
using PX.Objects.SO.Standalone;
using PX.Objects;
using PX.Objects.SO;
using CFMWT22072024;

namespace PX.Objects.SO
{
public class SOOrderEntry_Extension : PXGraphExtension<PX.Objects.SO.SOOrderEntry>
{
#region Event Handlers
protected void SOLine_UsrAnticipatedInvDate_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
{
var row = e.Row as SOLine;
if (row == null) return;

// Fetch the Sales Order
SOOrder order = PXSelect<SOOrder,
Where<SOOrder.orderNbr, Equal<Required<SOOrder.orderNbr>>>>
.Select(Base, row.OrderNbr);
if (order == null) return;

// Fetch the Terms
Terms terms = PXSelect<Terms,
Where<Terms.termsID, Equal<Required<Terms.termsID>>>>
.Select(Base, order.TermsID)
.RowCast<Terms>()
.FirstOrDefault();
if (terms == null) return;

// Get the anticipated invoice date from SOLine
SOLineExt soLineExt = sender.GetExtension<SOLineExt>(row);
DateTime? anticipatedInvoiceDate = soLineExt.UsrAnticipatedInvDate;
if (anticipatedInvoiceDate == null) return;

// Get the payment terms days
int termsDays = terms.DayDue00.GetValueOrDefault();

// Fetch the Location
//Location location = PXSelect<Location,
// Where<Location.bAccountID, Equal<Required<Location.bAccountID>>,
// And<Location.locationID, Equal<Required<Location.locationID>>>>>
// .Select(Base, order.CustomerID, order.CustomerLocationID)
// .RowCast<Location>()
// .FirstOrDefault();
//if (location == null) return;

// Get the Location extension to access custom fields
// LocationExt locationExt = PXCache<Location>.GetExtension<LocationExt>(location);
// Fetch the Location using the CRLocation alias
CRLocation location = PXSelect<CRLocation,
Where<CRLocation.bAccountID, Equal<Required<CRLocation.bAccountID>>,
And<CRLocation.locationID, Equal<Required<CRLocation.locationID>>>>>
.Select(Base, order.CustomerID, order.CustomerLocationID)
.RowCast<CRLocation>()
.FirstOrDefault();
if (location == null) return;

// Get the Location extension to access custom fields
StandaloneLocationExt locationExt = PXCache<CRLocation>.GetExtension<StandaloneLocationExt>(location);

if (locationExt?.UsrExpectedPaymentDate == null) return;

// Get the additional days from the Location UDF
int additionalDays = locationExt.UsrExpectedPaymentDate.Value.Day;

// Calculate the final expected payment date:
// Anticipated Invoice Date + Terms Days + Additional Days from Location
DateTime expectedPaymentDate = anticipatedInvoiceDate.Value
.AddDays(termsDays)
.AddDays(additionalDays);

// Update the expected payment date in the SOLine
sender.SetValueExt<SOLineExt.usrExpectedPaymentDate>(row, expectedPaymentDate);
}
}
}

How can I access this field in order to process my calculation?

Any help would be appreciated, thank you!

Hi @TharidhiP,

To access custom field from Shipping tab of Customers screen from SOOrderEntry graph,

You need to replace

StandaloneLocationExt locationExt = PXCache<CRLocation>.GetExtension<StandaloneLocationExt>(location);

to

 LocationExt locationExt = PXCache<CRLocation>.GetExtension<LocationExt>(location);

Add PX.Objects.CR.Standalone namespace to SOOrderEntry graph.

i.e. using PX.Objects.CR.Standalone;

Hope, it helps!
 


Hi @TharidhiP ,

If you add both extension classes under the same namespace, the error does not occur.
 

 


Thank you for the suggestion, it works now! @Dipak Nilkanth @jinin 


Reply