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.

  • Shane C Erstad Profile Picture
    on at
    RE: Select Control doesn't populate - View Extension (MPOS)

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

  • Adolfome9 Profile Picture
    110 on at
    RE: Select Control doesn't populate - View Extension (MPOS)

    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
    RE: Select Control doesn't populate - View Extension (MPOS)

    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.

  • ToddB Profile Picture
    on at
    RE: Select Control doesn't populate - View Extension (MPOS)

    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.

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,261 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,009 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans