Skip to main content
Answer

How to set the owner of a shipment to whomever clicked the Create Shipment button in a Sales Order

  • February 28, 2024
  • 1 reply
  • 110 views

I am trying to set the Owner field in a shipment to whomever clicked the Create Shipment button on the Sales Order that the shipment is related to.  Scoured the web but I am unable to find anything related to this and I am new to Acumatica in general.  Any help is appreciated. 

Best answer by Zoltan Febert

Hi @kevinwedemeier,

You need to override SetShipmentFieldsFromOrder function in SOShipmentEntry.
Owner is a Contact, so once you have the UserID, you can get ContactID from Contact table.

using System;
using PX.Data;
using PX.Data.BQL;
using PX.Data.BQL.Fluent;
using PX.Objects.CR;

namespace PX.Objects.SO
{
// Acuminator disable once PX1016 ExtensionDoesNotDeclareIsActiveMethod extension should be constantly active
public class SOShipmentEntryExt : PXGraphExtension<SOShipmentEntry>
{
[InjectDependency]
public ICurrentUserInformationProvider UserInformationProvider { get; set; }

[PXOverride]
public virtual bool SetShipmentFieldsFromOrder(
SOOrder order,
SOShipment shipment,
int? siteID,
DateTime? shipDate,
string operation,
SOOrderTypeOperation orderOperation,
bool newlyCreated,
Func<SOOrder, SOShipment, int?, DateTime?, string, SOOrderTypeOperation, bool, bool> baseMethod)
{
var contact = (Contact)SelectFrom<Contact>
.Where<Contact.userID.IsEqual<@P.AsGuid>>
.View.Select(Base, UserInformationProvider.GetUserId());
shipment.OwnerID = contact?.ContactID;

return baseMethod(order, shipment, siteID, shipDate, operation, orderOperation, newlyCreated);
}
}
}

 

1 reply

Zoltan Febert
Jr Varsity I
Forum|alt.badge.img+3
  • Jr Varsity I
  • Answer
  • February 29, 2024

Hi @kevinwedemeier,

You need to override SetShipmentFieldsFromOrder function in SOShipmentEntry.
Owner is a Contact, so once you have the UserID, you can get ContactID from Contact table.

using System;
using PX.Data;
using PX.Data.BQL;
using PX.Data.BQL.Fluent;
using PX.Objects.CR;

namespace PX.Objects.SO
{
// Acuminator disable once PX1016 ExtensionDoesNotDeclareIsActiveMethod extension should be constantly active
public class SOShipmentEntryExt : PXGraphExtension<SOShipmentEntry>
{
[InjectDependency]
public ICurrentUserInformationProvider UserInformationProvider { get; set; }

[PXOverride]
public virtual bool SetShipmentFieldsFromOrder(
SOOrder order,
SOShipment shipment,
int? siteID,
DateTime? shipDate,
string operation,
SOOrderTypeOperation orderOperation,
bool newlyCreated,
Func<SOOrder, SOShipment, int?, DateTime?, string, SOOrderTypeOperation, bool, bool> baseMethod)
{
var contact = (Contact)SelectFrom<Contact>
.Where<Contact.userID.IsEqual<@P.AsGuid>>
.View.Select(Base, UserInformationProvider.GetUserId());
shipment.OwnerID = contact?.ContactID;

return baseMethod(order, shipment, siteID, shipDate, operation, orderOperation, newlyCreated);
}
}
}