Hi, How can we get custom fields into SC categorie...
# suitecommerce
m
Hi, How can we get custom fields into SC categories? 19.2 version Any article?
s
It is not natively supported so I believe the recommended approach would be to write a service that fetches them
m
For the previous versions like Kilimanjaro it was supporting I guess?
s
I don't think the native categories service file ever fetched a category's custom fields
m
If I call a service how can I incorporate into SC.categories? Before the site loads?
s
Actually you probably don't need a service and can just use events. Write some SuiteScript that does something like:
Copy code
Application.on('after:Category.get', function () {
  var customfield = nlapiLookupField('commercecategory', category.internalid, [
    'yourcustomfield'
  ]);
  return customfield
});
And then have some code that attaches that value to the model for the commerce category
m
I just tried with pcv in categories.ts... just to check if it's anything to do with.. but no luck
I'll try with what you said. Thank you @Steve Goldberg
Hi @Steve Goldberg, I've tried the method it didn't work. It says internalid error
And moreover this will work only for individual categories right?
What I actually want is to get the custom commerce fields data and manipulate something in the Navigation menu based on the results.
s
After I sent you that someone sent me this, which is more complete:
Copy code
Application.on('after:Category.get', function (CategoryModel, category) {
    var lookupResults = nlapiLookupField('commercecategory', category.internalid, [
        'yourcustomfield'
    ]);
    category.customfield = lookupResults.yourcustomfield
});
This person's solution takes full advantage of what the event wrapper offers and modifies the category object as it is passed through, so the whole thing is seamless
m
Yes @Steve Goldberg this is working great. I could able to get the data when I go to individual categories. So how it works for Navigation bar (Menu)? I guess the menu will form from search API right?
I'm want to manipulate level 1/2/3 categories from the resulting data....
Any help on this please?