How to add new column from and exiting column using a parser funtion?

Answered

Comments

2 comments

  • Saul Ackerman

    You can have a function running within the parser that extracts the last 4 digits, and point a new column to that function. For example, take a standard CSV upload with the 8 required column

     

    function parse(data){
        return data.map(function(prod) {
          return {
            sku: prod.sku,
            name: prod.name,
            categories: prod.categories,
            group_id: prod.group_id,
            price: prod.price,
            in_stock: prod.in_stock,
            url: prod.url,
            image_url: prod.image_url,
            keywords:prod.keywords,
          last_four: getLAstFourDigits(prod.group_id)
          }
        })
    }

    function getLAstFourDigits(group_id){
    return groupId.slice(-4);
    }
    Comment actions Permalink
  • Mehroz Shahid

    Thanks Saul.

    We were able to achieve it with this funtion

      // [DY] Set "colorID" column
            products[item.sku]['ColorID'] = item.group_id.slice(item.group_id.length - 4);

    Comment actions Permalink

Please sign in to leave a comment.