web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Supply chain | Supply Chain Management, Commerce
Unanswered

Select Control doesn't populate - View Extension (MPOS)

(0) ShareShare
ReportReport
Posted on by 110

Hello everyone,

I'm new to customizing the MPOS (D365 Commerce) and I'm trying to fill the "Select" control with data from the database. I have validated that my controller (Api) returns the required information, however it is not reflected in the view (Cart).

import {
CartViewCustomControlBase,
ICartViewCustomControlState,
ICartViewCustomControlContext,
CartChangedData
} from "PosApi/Extend/Views/CartView";

import {
ObjectExtensions,
StringExtensions,
ArrayExtensions
} from "PosApi/TypeExtensions";

import { ProxyEntities, ClientEntities } from "PosApi/Entities";
import { TipoComprobanteApiPE } from "../../DataService/DataServiceRequests.g";
import { Entities } from "../../DataService/DataServiceEntities.g";
import MessageDialog from "../../DialogSample/MessageDialog";

export default class SalesCustomControl extends CartViewCustomControlBase {

private _cart: Observable<ProxyEntities.Cart>;
public documentTypeIdPE: Observable<string>;

public documentTypeListPE: ObservableArray<Entities.TipoComprobantePEEntity>;

private _context: ICartViewCustomControlContext;
private _state: ICartViewCustomControlState;

private static readonly TEMPLATE_ID: string = "Microsoft_Pos_Extensibility_Samples_Sales";
public readonly documentTypePELabel: string;

constructor(id: string, context: ICartViewCustomControlContext) {
super(id, context);

/* Start fixed values*/
let tp1: Entities.TipoComprobantePEEntity = new Entities.TipoComprobantePEEntity();
tp1.TipoComprobanteId = "-";
tp1.TipoComprobante = "--DEFAULT--";

let tp2: Entities.TipoComprobantePEEntity = new Entities.TipoComprobantePEEntity();
tp2.TipoComprobanteId = "01";
tp2.TipoComprobante = "INVOICE";
/* End fixed values*/

this._context = context;

this.documentTypeIdPE = ko.observable("");


this.documentTypeListPE = ko.observableArray([tp1, tp2]);

this.documentTypePELabel = this._context.resources.getString("string_50");

this._cart = ko.observable(null);

this.cartChangedHandler = (data: CartChangedData) => {


this._cart(data.cart);


};

this.documentTypeIdPE.subscribe((newValue: string): void => {


this._addOrUpdateExtensionProperty("DOCUMENTTYPEID", <ProxyEntities.CommercePropertyValue>{ StringValue: newValue });


});


}

public onReady(element: HTMLElement): void {


ko.applyBindingsToNode(element, {
template: {
name: SalesCustomControl.TEMPLATE_ID,
data: this
}
});


}

public init(state: ICartViewCustomControlState): void {


this._state = state;

let correlationIdDT: string = this._context.logger.getNewCorrelationId();
let requestTP: TipoComprobanteApiPE.GetTipoComprobanteRequest<TipoComprobanteApiPE.GetTipoComprobanteResponse> = new TipoComprobanteApiPE.GetTipoComprobanteRequest();

this._context.runtime.executeAsync(requestTP)
.then((result: ClientEntities.ICancelableDataResult<TipoComprobanteApiPE.GetTipoComprobanteResponse>): void => {

if (!(result.canceled || ObjectExtensions.isNullOrUndefined(result.data))) {

let myResult: Entities.TipoComprobantePEEntity[] = [];

result.data.result.forEach((nRow: Entities.TipoComprobantePEEntity): void => {
myResult.push(nRow);


//It returns all values that I expect.
});

this.documentTypeListPE(myResult);


}
})
.catch((reason: any) => {


this._context.logger.logError(JSON.stringify(reason), correlationIdDT);


});

}

/**
* Gets the property value from the property bag, by its key. Optionally creates the property value on the bag, if it does not exist.
*/
private _addOrUpdateExtensionProperty(key: string, newValue: ProxyEntities.CommercePropertyValue): void {


let cart: ProxyEntities.Cart = this._cart();

let extensionProperty: ProxyEntities.CommerceProperty = Commerce.ArrayExtensions.firstOrUndefined(cart.ExtensionProperties, (property: ProxyEntities.CommerceProperty) => {
return property.Key === key;
});

if (ObjectExtensions.isNullOrUndefined(extensionProperty)) {
let newProperty: ProxyEntities.CommerceProperty = {
Key: key,
Value: newValue
};

if (ObjectExtensions.isNullOrUndefined(cart.ExtensionProperties)) {
cart.ExtensionProperties = [];
}

cart.ExtensionProperties.push(newProperty);


} else {


extensionProperty.Value = newValue;


}

this._cart(cart);


}


}

***********************************************************************

If I add fixed values to my variable "documentTypeListPE" it shows as I expected.

pastedimage1608240504513v1.png

I will be grateful for the help you can give me.

thanks in advance.

I have the same question (0)
  • ToddB Profile Picture
    on at

    Hi Adolfo,

    I am checking to see what I can find in regard to this; and will also leave this for the community to reply as well.

  • Shane C Erstad Profile Picture
    on at

    Adolfo,

    Based on the comment in the code, it looks like you verified that the init() runs and the call to get the data (GetTipoComprobanteRequest) works fine.

    I wonder if the fact that you already populated the dropdown in the constructor (with the two default values) is causing the dropdown to be fixed at just those two values:

           this.documentTypeListPE = ko.observableArray([tp1, tp2]);

    Have you tried leaving the code out and seeing if the code in the init populates the list?

    If you're still having problems, you may want to open a support request to get some assistance.

  • Adolfome9 Profile Picture
    110 on at

    Hi Shane;

    Thank you for your comment, I have solved it checking log event viewer. In method "_addOrUpdateExtensionProperty" wasn't properly controlled undefined value for cart variable.

  • Shane C Erstad Profile Picture
    on at

    Thanks for the update - glad to hear you were able to get it going.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Supply chain | Supply Chain Management, Commerce

#1
Siv Sagar Profile Picture

Siv Sagar 283 Super User 2025 Season 2

#2
Laurens vd Tang Profile Picture

Laurens vd Tang 213 Super User 2025 Season 2

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 152 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans