Retrieving Item Field Values SuiteCommerce SS1

in , , August 10th, 2024

When working in SuiteScript, there are many occasions when you might need to retrieve field values from an item. You might think to load each item record and search or get the value for each field ID. Passing a field set to getItemFieldValues() is a more concise way of accomplishing that.

getItemFieldValues

The getItemFieldValues function retrieves values from items in the shopping context.

For more information on the shopping context, check out this training article on the SuiteCommerce Shopping Object.

You can define a field set in the website setup record and pass this field set into getItemFieldValues() to retrieve specific item fields by id.

  • See line 45 of the example below for method call:
var addOnItems = ModelsInit.session.getItemFieldValues('addonitems', addOnItemIds).items;
  • The first parameter passed into the function is the field set id. “addOnItemIds” is an array of items.
  • Items can be accessed by the “items” attribute returned in the object from getItemFieldValues().

Example Solution Code

define('AddOnItems.Model',
    [
        'SC.Model',
        'SC.Models.Init',
        'underscore'
    ],
function (
        SCModel,
        ModelsInit,
        _
) 
{
    'use strict';


    return SCModel.extend({


        name: 'AddOnItems.Model',


        getAddOnItems: function (data) {


            var returnObj = {};


            try {
                var columns = _.pluck(data.addOnItemsConfig, 'fieldId'),


                    fieldValues = nlapiLookupField('item', data.itemId, columns),


                    addOnItemIds = [];
                    
                addOnItemsConfig = _.map(data.addOnItemsConfig, function (configType) {


                    var field_value = fieldValues[configType.fieldId];


                    configType.itemIds = field_value ? field_value.split(',') : [];


                    addOnItemIds = _.union(configType.itemIds, addOnItemIds);


                    return configType;
                });


                addOnItemIds = _.uniq(addOnItemIds);


                if (addOnItemIds.length) {


                    var addOnItems = ModelsInit.session.getItemFieldValues('addonitems', addOnItemIds).items;


                }
            }
            catch (e) {
                returnObj.error = e;
            }


            return returnObj;
        }
    });
}
);

 Author: An Phan


Got stuck on a step in this article?

We like to update our blogs and articles to make sure they help resolve any troubleshooting difficulties you are having. Sometimes, there is a related feature to enable or a field to fill out that we miss during the instructions. If this article didn't resolve the issue, please use the chat and let us know so that we can update this article!


Oracle NetSuite Alliance Partner & Commerce Partner

If you have general questions about SuiteCommerce or more specific questions about how our team can support your business as you implement NetSuite or SuiteCommerce, feel free to contact us anytime. Anchor Group is a certified Oracle NetSuite Alliance Partner and Commerce Partner equipped to handle all kinds of NetSuite and SuiteCommerce projects, large or small!

We are a premium SuiteCommerce agency that creates powerful customer portals. Unlike our competitors, we have already solved your problems.

 
 

Want to keep learning?

Our team of NetSuite professionals has written articles on a wide variety of NetSuite topics, from SuiteCommerce tips, to recommended NetSuite solutions, to available support services, and more! 

Your cart