question

Devon avatar image
Devon asked

Problem only with GetCatalogItems

So I have this super simple code here in CloudScript:

    var allCatalogItems = server.GetCatalogItems({
        CatalogVersion : args.catalogVersionEM.toString()
        });

Line 319, title 6B666, I get an item from a result table, grant and apply some custom data, then get the catalog custom data via GetCatalogItems, then apply the custom data drawn from there at random.

I check it via allCatalogItems.length displayed as a debuglog in the event history, which returns "undefined". The specified catalog displays accurately. I've tried with and without toString(). Calls still work before and after it. I put it in the debug log directly to see if it was a scope problem.

No luck with using postman still, but I've done plenty of these calls before, and I've checked multiple times that it matched, but with GetCatalogItems in specific refuses to work.

Maybe I just need to sleep on it to see what I'm missing.

CloudScript
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Seth Du avatar image
Seth Du answered

According to your description, allCatalogItems you have defined is the callback result of GetCatalogItems API, which is an Obejct. In JavaScript, we cannot use Object.length to retrieve the length of an object and it will return a similar error like undefined.

Meanwhile, what you want to get is the length of Catalog property in the response, which is array list ofCatalogItem type. Please refer to the API document: GetCatalogItems and note the correct format of the response. You can use either allCatelogItems.Catalog.length or allCatalogItems[‘Catalog’].length to get your required data.

If you have any further questions, please let me know.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Devon avatar image Devon commented ·

Got it, thanks!

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.