When trying to get customer segments within the sh...
# suitecommerce
m
When trying to get customer segments within the shopping entrypoint it fails, but on my_account entrypoint it works fine. Is this expected behavior?
Copy code
var userProfile = container.getComponent('UserProfile');
userProfile.getCustomerSegments().then(function(customerSegments) {
    console.debug({customerSegments});
}).fail(function(reason) {
    console.debug({reason});
});
on shopping returns the following error:
Copy code
Cannot read properties of undefined (reading 'map')
on my_account it returns successfully:
Copy code
{
  "customerSegments": [
    {
      "id": -1,
      "name": "-- ALL USERS --"
    },
    {
      "id": -3,
      "name": "-- RECOGNIZED AND LOGGED-IN CUSTOMERS --"
    },
    {
      "id": 7413,
      "name": "PCV: Food Pantry NE USDA"
    }
  ]
}
s
That's odd. Have you tried wrapping that in something that waits for the UserProfile promise to resolve first? Eg
Copy code
userProfile.getUserProfile().then( ... your code here ...)
Shopping doesn't need to wait for the user profile promise to resolve for it to load but the my account application does, which would explain why the my account application works fine.
m
Thanks for your suggestion. That worked. Maybe it's because the I put the code in the entry point instead of the view?
s
Ah, well yes. Entry point files are loaded at application load, views are much further down the chain and so will typically have finished promises by then