Skip to main content
Answer

Unable to cast object of type System.Guid to type System.String

  • April 8, 2022
  • 7 replies
  • 1254 views

Forum|alt.badge.img

Hi there,

 

I am trying to override the address line 1 on Shipment screen by defaulting it to the User Defined Field selection (pointing to Customer table). However, when I got this error when I try to test it:

 

Below is my DAC as well as code for your reference:

DAC:

using System;
using PX.Data;
using PX.Data.BQL;
using PX.Objects.SO;

namespace PX.Objects.SO
{
[Serializable]
[PXCacheName("SOShipmentKvExt")]
public class SOShipmentKvExt : IBqlTable
{
public abstract class recordID : BqlGuid.Field<recordID> { }
[PXDBGuid(IsKey = true)]
public Guid? RecordID { get; set; }

public abstract class fieldName : BqlString.Field<fieldName> { }
[PXDBString(50,IsKey = true)]
[PXUIField(DisplayName ="Name")]
public string FieldName { get; set; }

public abstract class valueNumeric : BqlDecimal.Field<valueNumeric> { }
[PXDBDecimal(8)]
[PXUIField(DisplayName = "Value Numeric")]
public decimal? ValueNumeric { get; set; }

public abstract class valueDate : BqlDateTime.Field<valueDate> { }
[PXDBDate]
[PXUIField(DisplayName = "Value Date")]
public DateTime? ValueDate { get; set; }

public abstract class valueString : BqlString.Field<valueString> { }
[PXDBString(256)]
[PXUIField(DisplayName = "Value String")]
public string ValueString { get; set; }

public abstract class valueText : BqlString.Field<valueText> { }
[PXDBString]
[PXUIField(DisplayName = "Value Text")]
public string ValueText { get; set; }
}
}

 

Code:

using PX.CS.Contracts.Interfaces;
using PX.Data.ReferentialIntegrity.Attributes;
using PX.Data;
using PX.Objects.CR;
using PX.Objects.CS;
using PX.Objects.SO;
using PX.Objects;
using System.Collections.Generic;
using System;

namespace PX.Objects.SO
{
// Acuminator disable once PX1011 InheritanceFromPXCacheExtension [Justification]
// Acuminator disable once PX1016 ExtensionDoesNotDeclareIsActiveMethod extension should be constantly active
// Acuminator disable once PX1026 UnderscoresInDacDeclaration [Justification]
[PXNonInstantiatedExtension]
public class SO_SOAddress_ExistingColumn : PXCacheExtension<PX.Objects.SO.SOAddress>
{
#region AddressLine1
[PXMergeAttributes(Method = MergeMethod.Append)]
[PXDBScalar(typeof(Search2<SOAddress.addressLine1,
InnerJoin<SOShipment, On<SOAddress.customerID, Equal<SOShipment.customerID>>,
InnerJoin<SOShipmentKvExt, On <SOShipment.noteID, Equal<SOShipmentKvExt.recordID>>>>,
Where<SOShipment.customerID, Equal<Current<SOShipmentKvExt.valueString>>>>))]
public string AddressLine1 { get; set; }
#endregion
}

}

 

I suspect it is because the UDF is being treated as String while the Customer ID is treated as GUID, but I may be wrong. Any idea on how to tackle this issue?

Best answer by Naveen Boga

Hi @ericklasimin61 Can you please like below and verify?

With the below code, I’m not seeing any object conversion issue.

 

[PXNonInstantiatedExtension]
public class SO_SOAddress_ExistingColumn : PXCacheExtension<PX.Objects.SO.SOAddress>
{
#region AddressLine1
[PXMergeAttributes(Method = MergeMethod.Merge)]
[PXDBScalar(typeof(Search2<SOAddress.addressLine1,
InnerJoin<SOShipment, On<SOAddress.customerID, Equal<SOShipment.customerID>>,
InnerJoin<BAccount, On<BAccount.bAccountID, Equal<SOShipment.customerID>>,
InnerJoin<SOShipmentKvExt, On<SOShipment.noteID, Equal<SOShipmentKvExt.recordID>>>>>,
Where<BAccount.acctCD, Equal<Current<SOShipmentKvExt.valueString>>>>))]
public string AddressLine1 { get; set; }
#endregion
}

 

7 replies

Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • April 8, 2022

Hi @ericklasimin61  Can you please also let us know how do you create the UDF field on the Shipment.

Can you please share the UDF attribute screenshot?


Forum|alt.badge.img
  • Author
  • Varsity I
  • April 8, 2022

Hi @Naveen Boga , here you go:

 

I initially tried with AcctCD but failed, then I changed it to ParentBAccountID, but similar result.


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • Answer
  • April 8, 2022

Hi @ericklasimin61 Can you please like below and verify?

With the below code, I’m not seeing any object conversion issue.

 

[PXNonInstantiatedExtension]
public class SO_SOAddress_ExistingColumn : PXCacheExtension<PX.Objects.SO.SOAddress>
{
#region AddressLine1
[PXMergeAttributes(Method = MergeMethod.Merge)]
[PXDBScalar(typeof(Search2<SOAddress.addressLine1,
InnerJoin<SOShipment, On<SOAddress.customerID, Equal<SOShipment.customerID>>,
InnerJoin<BAccount, On<BAccount.bAccountID, Equal<SOShipment.customerID>>,
InnerJoin<SOShipmentKvExt, On<SOShipment.noteID, Equal<SOShipmentKvExt.recordID>>>>>,
Where<BAccount.acctCD, Equal<Current<SOShipmentKvExt.valueString>>>>))]
public string AddressLine1 { get; set; }
#endregion
}

 


Forum|alt.badge.img
  • Author
  • Varsity I
  • April 8, 2022

Hi @Naveen Boga , the code you provided works! But the address line 1 remains unchanged. I’m pretty sure the logic is correct, or am I missing something?


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • April 8, 2022

Hi, @ericklasimin61  Object Conversion issue is gone now, and thanks for the update.

Can you please explain your exact requirement? so that I can check from my end. 


Forum|alt.badge.img
  • Author
  • Varsity I
  • April 10, 2022

@Naveen Boga , my exact requirement is that when I select the customer from UDF (only visible for Transfer) in Shipments screen, the Contact and Address will be auto-populated based on UDF selection.


Forum|alt.badge.img
  • Freshman II
  • July 29, 2024

thanks