November Happy Hour will be moved to Thursday December 5th.

Custom Metafield in Purchase Order and View in Commerce

P
P
Vote:
 

Hi Everyone,

I have a requirement to add custom metafileds to purchase order class.

i used below code to add metafield.

var name = "AccountName";
var metaNamespace = "Mediachase.Commerce.Orders.PurchaseOrder";
var friendlyName = "Account Name";
var description = string.Empty;
var metaFieldType = MetaDataType.LongString;
var isNullable = true;
var length = 0;
var isMultiLanguage = false;
var isSearchable = false;
var isEncrypted = false;

var metaClass = OrderContext.Current.PurchaseOrderMetaClass;
if (metaClass.MetaFields.Any(x => x.Name == name))
return false;

var metaContext = OrderContext.MetaDataContext;

var metaField = MetaField.Create(metaContext,metaNamespace,name,friendlyName,description,metaFieldType,length,isNullable,isMultiLanguage,isSearchable,isEncrypted);

metaClass.AddField(metaField);

Adding value to this proprty as

purchaseOrder[OrderFields.AccountName] = cart.GetOrganization().Name.ToString();

Now the task is How can I show this field in Purchace Order List in Commerce.

Please share your comments on this.

Thank you!!

#218017
Edited, Mar 04, 2020 9:15
Vote:
 

I haven't tested it, but you might be able to edit Apps\Order\Config\View\Grids\Orders-List.xml, and add a column into Columns section, like this

<Column width="200" allowSorting="false" dataField="AccountName" headingText="Account Name"></Column>

Note that this is not officially supported, and you will loose your change once you upgrade (i.e. you have to re-apply)

#218018
Mar 04, 2020 9:19
P - Mar 11, 2020 4:04
hi Quan, thanks for the reply.
When i added directly like this , i'm getting this exception
"DataBinding: 'Mediachase.Commerce.Orders.PurchaseOrder' does not contain a property with the name 'AccountName'."
It's allowing that, whatever fields are directly available in the PurchaseOrder Class.

Vote:
 

It is highly recommended that you make the change through an xml transformation, that way you can automatically re-apply it when upgrading.

Here is an example where we add a column to the list of payments on an PurchaseOrder, PurchaseOrder-ObjectView-Transform.xml:

<?xml version="1.0" encoding="utf-8" ?>
<!-- For more information on using transformations 
     see the web.config examples at http://go.microsoft.com/fwlink/?LinkId=214134. -->
<View xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xmlns="http://schemas.mediachase.com/ecf/view">
  <Form>
    <Grids>
      <add>
        <Grid placeName="OrderPayment-List" xdt:Locator="Match(placeName)">
          <Columns>
            <Column width="100" visible="true" allowSorting="false" dataField="TransactionID" headingText="Transaction ID" xdt:Locator="Match(dataField)" xdt:Transform="InsertIfMissing"></Column>
          </Columns>
        </Grid>
      </add>
    </Grids>
  </Form>
</View>
#218033
Mar 04, 2020 16:02
P - Mar 11, 2020 12:09
Thanks for the reply Erik,

As you said its working fine for Payments, but when came to orders list, its throwing an exception.
P
Vote:
 

Hi all,

I was added meta fields to Purchase Order, but unable to bind the same in commerce view.

Getting an error, if i mentioned custom property in Orders-List.xml as

"DataBinding: 'Mediachase.Commerce.Orders.PurchaseOrder' does not contain a property with the name 'AccountNumber'."

in Ordrs-List.xml I was added below line

<Column width="100" allowSorting="true" dataField="AccountNumber" headingText="Account Name"></Column>

#218353
Mar 11, 2020 11:52
Vote:
 

Now I looked into my book, it looks like you will need to use a custom template, basically like this

<Column width="150" allowSorting="true" dataField="AccountNumber" headingText="Account number" Align="Center" columnType="CustomTemplate">
<Template id="OrderStatusTemplate" controlUrl="GridTemplates/AccountNumber.ascx"></Template>
</Column>

Now it's quite conflicted, I wrote it in detail here https://leanpub.com/epicommercerecipes if you want to buy it, but if you don't, AccountNumber.ascx is just a simple user control that needs to inherit/implement BaseUserControl, IEcfListViewTemplate

#218354
Mar 11, 2020 12:06
P - Mar 13, 2020 11:14
Thank you Quan Mai!!

We bought your EBook bundle, and referred "Epicommercerecipes". I was fixed my customization for order list in commerce.
It's Awesome Quan. Thanks Again.
Quan Mai - Mar 13, 2020 11:17
Glad you liked it and thanks for your purchase!
P
Vote:
 

Hi Quan,

May I know that whether we can have an Account Name from Purchase order instead of using Contact ID?

When we are using ConctId, Account details are updating to latest ones when user can have multiple accoutns.

Thank you!

#218711
Mar 19, 2020 5:52
Vote:
 

Not sure if I understand you correctly, but you can just set AccountName metafield to the contact name when you create the order.

#218714
Mar 19, 2020 7:03
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.