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
Answered

Get the value out of a TypeScript Promise for a value on a grid column

(0) ShareShare
ReportReport
Posted on by 1,457

I need to get the employee's name to show in the search order view grid (OrderSearchViewColumns.ts) as a column.

Here Oksana helped me to get the value from the employee request/response pair on a typescript file that shows just fields:

https://community.dynamics.com/365/commerce/f/dynamics-365-commerce-forum/380463/how-to-find-employee-record-in-custom-control

How do I add it to a column grid?

Here is my attempt:

****

export default (context: ICustomColumnsContext): IOrdersListColumn[] => {

    return [
        {
            title: context.resources.getString("tmc_20"), //"SALES ORDER",
            computeValue: (row: ClientEntities.ISalesOrderDetails): string => {
                return row.salesOrder.SalesId;
            },
            ratio: 10,
            collapseOrder: 8,
            minWidth: 100
        },

        {
            title: context.resources.getString("tmc_41"), // "SALES TAKER",
            computeValue: (row: ClientEntities.ISalesOrderDetails): string => {
                if (!ObjectExtensions.isNullOrUndefined(row.salesOrder.StaffId)) {
                    let runtime: IRuntime = context.runtime;  
                    return runtime.executeAsync(new GetLoggedOnEmployeeClientRequest(row.salesOrder.StaffId))
                        .then((response: ClientEntities.ICancelableDataResult<GetLoggedOnEmployeeClientResponse>): ProxyEntities.Employee => {
                            return response.data.result;
                        })
                        .then((results: ClientEntities.ICancelableDataResult<ProxyEntities.Employee>): ProxyEntities.Employee => {
                            return results.data;
                        })
                        .then((empl: ProxyEntities.Employee): string => {
                            return empl.Name;
                        })
                        .catch(() => {
                            return StringExtensions.EMPTY;
                        });
                }
                return StringExtensions.EMPTY;
            },
            ratio: 10,
            collapseOrder: 6,
            minWidth: 100
        },
...
...
...
...

****

I get this error however:

pastedimage1588790926586v1.png

The first "then" receives the promise. The 2nd "then" is supposed to receive the actual employee record and then the 3rd "then" is supposed to retrieve the name on the employee record. This is how I understood the promise is working. But it seems I am still not understanding how Promise is working because I just can't get to the actual record.

Any help is much appreciated.

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

    We need test your code in environment and find possible solution

  • Suggested answer
    Ramshenkar Profile Picture
    on at

    I believe you don't required the second '.then' block.

    Your first '.then' is of return type 'ProxyEntities.Employee' and second '.then' is accepting parameter 'ClientEntities.ICancelableDataResult<ProxyEntities.Employee>' which are not compatible.

    Your third '.then' block accepting the parameter 'ProxyEntities.Employee' and that is what return by first '.then' block. 

    Try using below code - 

    .then((response: ClientEntities.ICancelableDataResult<GetLoggedOnEmployeeClientResponse>): ProxyEntities.Employee => {
    return response.data.result;
    })
    .then((empl: ProxyEntities.Employee): string => {
    return empl.Name;
    })

  • Retha Profile Picture
    1,457 on at

    I will try this.

    I tried to use CRT but it isn't working either because on the SearchOrderServiceRequest, one works with the SalesOrder entity. Even though it has the field: StaffId, the latter is blank. This grid is filled with a realtime call to the AOS. I don't want to do another realtime call, it will kill the performance. I am trying to get the staff name from the channel DB instead.

    However, table RetailTranactionTable , even though it has the SalesOrderId field, the latter is blank. It has only the TransactionID. SalesOrder has only the SalesID, no TransactionId. RetailTransactonTable has the Staff id populated.

    So if it was possible to retrieve the RetailTransactionTable record for the SalesOrder entity record, then I could have used the staff id on RetailTransactionTable to call EmployeesView and retrieve the name.

    But with fields not being populated even though they are there, makes it impossible,

  • Verified answer
    Ramshenkar Profile Picture
    on at

    You don't need to real-time service call again.

    1. Identity the rts method

    2. Extend in X++ using COC technique

    3. Popolate the missing data in sales Order entity.

    4. You will get that in CRT.

    Step 3 will be little bit complex as you have to modify the XML object which will be returned by rts method.

    Note : Usually such requirements ask to show SalesCommissionGroup (sales person for the transaction or line) field instead of Staffid. Please check.

  • Retha Profile Picture
    1,457 on at

    Thanks Ram.

    I used these steps to extend the X++ code.  I extended class RetailTransactionServiceTransactions method fillSalesOrderDetails and class RetailTransactionServiceTransactionsJson method fillSalesOrderDetails.

    If the staffID is blank and SalesTable exist, I get the staffId from HCMWorker.PersonnelNumber via SalesTable.WorkerSalesTaker.

    Then I use in my CRT call to the channel DB this now populated staffID to read EmployeesView to get the name linked to the staffID to show on the grid.

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
Laurens vd Tang Profile Picture

Laurens vd Tang 271 Super User 2025 Season 2

#2
Siv Sagar Profile Picture

Siv Sagar 171 Super User 2025 Season 2

#3
André Arnaud de Calavon Profile Picture

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

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans