function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
iaestemaniaesteman 

Getting all product orders with sub products with lightning component

Hello,

I am trying to retrieve all Order Items with a lightning component that will be shown on the Account. But before that I want to explain my structure.
I have product bundles that have object bundle_line_items__c. There is a lookup field inside that connects the bundle_name__c(bundle) and bundle_child__c sub products.
Looks like this.

User-added image
So when I list the product bundle it has his own bundle_line_items in it.

Now, when i want to add that bundle to an order/Order Product i can do it easly. Showing the bundle line items is a bit hard, and that is what exactly i want to achieve.

I created a component with the code below that somehow i can get the order products and the bundle line items in that product to be visible for the sales guy. But code doesn't work and i don't know where i am making a mistake :(

apex class: 

public class MyOrdersListController {
@AuraEnabled
public static List<Order> getOrders(Id recordId) {
   return [select id from order Where AccountId = :recordId];
}
}
ProductOrdersComponent
ProductOrdersComponent.cmp
<aura:component controller="MyOrdersListController" implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<aura:attribute name="recordId" type="Id" />
<aura:attribute name="Account" type="Account" />
<aura:attribute name="Order" type="Order" />
<aura:attribute name="Columns" type="List" />
<aura:handler name="init" value="{!this}" action="{!c.myAction}" />
<force:recordData aura:id="accountRecord"
                  recordId="{!v.recordId}"
                  targetFields="{!v.Account}"
                  layoutType="FULL"
                  />
<lightning:card iconName="standard:contact" title="{! 'Order List for ' + v.Account.Name}">
<lightning:datatable data="{! v.Orders }" columns="{! v.Orders }" keyField="Id" hideCheckboxColumn="true"/>
</lightning:card>
</aura:component>
ProductOrdersComponent.js
({
	myAction : function(component, event, helper) {
        component.set("v.Orders", [
            {label:"id", fieldName:"Id", type:"text"}
        ]);

        var action = component.get("c.getOrders");
        action.setParams({
            recordId: component.get("v.recordId")
        });
        action.setCallback(this, function(data) {
            component.set("v.Orders", data.getReturnValue());
        });
        $A.enqueueAction(action);
	}
})


What I am missing? Any help will be highly appreciated.

The component should be shown on the account image below.
User-added image

with possible Nested Tree like in the link:

https://developer.salesforce.com/docs/component-library/bundle/lightning:tree/example#lightningcomponentdemo:exampleTreeWithMetatext

Thanks,

Darko

Naveen KNNaveen KN
@Darko
I recommend using console.log at client side js file and system.debug at apex code to see the output of variables.

Check whether you are getting the output to the client side. i.e what is the value at data.getReturnValue()

Sudha
Team codengine.in