Associating Items to Pallet ID's

Comments

6 comments

  • Tyler Lamparter Principal Product Manager
    Awesome Follow-up
    Engaged
    Top Contributor
    Answer Pro
    Celigo University Level 4: Legendary

    Jack Harris something like this?

    function transform (options) {
      const record = options.record;
      const transformedRecord = { items: [] };

      if (record.HL) {
        const parentItems = record.HL.filter(item => item.HierarchicalLevelCode === 'P');
        const childItems = record.HL.filter(item => item.HierarchicalLevelCode === 'T');

        parentItems.forEach(parentItem => {
          const lineNumber = parentItem.LineNumber;
          const matchingChildItem = childItems.filter(childItem => childItem.LineNumber === lineNumber);

          if (matchingChildItem) {
            for (let c of matchingChildItem) {
              const item = {
                Item: parentItem.Item,
                Lot: parentItem.Lot,
                SSCC18PalletID: c.MAN[0].SSCC18PalletID
              };
      
              transformedRecord.items.push(item);
            }
          }
        });
      }

      return {
        originalRecord: record,
        addedAssociations: transformedRecord.items
      };
    }

     

    For reference, I used Celigo AI from our release yesterday and it got me 95% of the way there. It was just giving me the first association it found instead of each one because it was using the Javascript "find" function instead of the "filter" function. After that, I just had to add a loop.

    function transform (options) {
      const record = options.record;
      const transformedRecord = { items: [] };

      if (record.HL) {
        const parentItems = record.HL.filter(item => item.HierarchicalLevelCode === 'P');
        const childItems = record.HL.filter(item => item.HierarchicalLevelCode === 'T');

        parentItems.forEach(parentItem => {
          const lineNumber = parentItem.LineNumber;
          const matchingChildItem = childItems.find(childItem => childItem.LineNumber === lineNumber);

          if (matchingChildItem) {
            const item = {
              Item: parentItem.Item,
              Lot: parentItem.Lot,
              SSCC18PalletID: matchingChildItem.MAN[0].SSCC18PalletID
            };

            transformedRecord.items.push(item);
          }
        });
      }

      return transformedRecord;
    }
    0
  • Tyler Lamparter Principal Product Manager
    Awesome Follow-up
    Engaged
    Top Contributor
    Answer Pro
    Celigo University Level 4: Legendary

    Jack Harris I actually followed up on the Celigo AI conversation and it came out with what I manually had to fix. So 100% good!

    function transform(options) {
      const record = options.record;
      const transformedRecord = { items: [] };

      if (record.HL) {
        const parentItems = record.HL.filter(item => item.HierarchicalLevelCode === 'P');
        const childItems = record.HL.filter(item => item.HierarchicalLevelCode === 'T');

        parentItems.forEach(parentItem => {
          const lineNumber = parentItem.LineNumber;
          const matchingChildItems = childItems.filter(childItem => childItem.LineNumber === lineNumber);

          if (matchingChildItems.length > 0) {
            matchingChildItems.forEach(matchingChildItem => {
              const item = {
                Item: parentItem.Item,
                Lot: parentItem.Lot,
                SSCC18PalletID: matchingChildItem.MAN[0].SSCC18PalletID
              };

              transformedRecord.items.push(item);
            });
          }
        });
      }

      return transformedRecord;
    }
    1
  • Jack Harris
    Celigo University Level 1: Skilled
    Engaged

    That's exactly what I was looking to do! So many thanks. Next I have to figure out why my handlebars in the File Parser don't work and I'll be golden.

     

    0
  • Tyler Lamparter Principal Product Manager
    Awesome Follow-up
    Engaged
    Top Contributor
    Answer Pro
    Celigo University Level 4: Legendary

    Jack Harris which handlebar?

    0
  • Jack Harris
    Celigo University Level 1: Skilled
    Engaged

    I eventually got that to work by putting in the relative path every time.

    Follow up question on the original question. I'm trying to add the Quantity shipped so I added a line to the code but it's not coming through the preview. Any ideas?

    0
  • Tyler Lamparter Principal Product Manager
    Awesome Follow-up
    Engaged
    Top Contributor
    Answer Pro
    Celigo University Level 4: Legendary

    Jack Harris not sure on your script, but here it is working on the one I sent.

    function transform(options) {
      const record = options.record;
      const transformedRecord = { items: [] };

      if (record.HL) {
        const parentItems = record.HL.filter(item => item.HierarchicalLevelCode === 'P');
        const childItems = record.HL.filter(item => item.HierarchicalLevelCode === 'T');

        parentItems.forEach(parentItem => {
          const lineNumber = parentItem.LineNumber;
          const matchingChildItems = childItems.filter(childItem => childItem.LineNumber === lineNumber);

          if (matchingChildItems.length > 0) {
            matchingChildItems.forEach(matchingChildItem => {
              const item = {
                Item: parentItem.Item,
                Lot: parentItem.Lot,
                SSCC18PalletID: matchingChildItem.MAN[0].SSCC18PalletID,
                Quantity: matchingChildItem.NumberOfUnitsShipped
              };

              transformedRecord.items.push(item);
            });
          }
        });
      }

      return {
        originalRecord: options.record,
        addedAssociations: transformedRecord.items
      };
    }

    0

Please sign in to leave a comment.