cancel
Showing results for 
Search instead for 
Did you mean: 

Can lookup table method be used with the Ruby Snippet Connector?

seemah123
Deputy Chef I
Deputy Chef I

Documentation referenced:
- Ruby Snippets by Workato: https://docs.workato.com/en/connectors/ruby-snippets-by-workato.html
- Available Ruby methods: https://docs.workato.com/en/developing-connectors/sdk/sdk-reference/ruby_methods.html#lookup 
I'm trying to understand how I might be able to use lookup() within the ruby snippet. The documentation implies that you should be able to, but whenever I try, I receive this error:

Lookup Tables are not initialized. Init data by calling LookupTable.from_file or LookupTable.load_data code.rb


The line I have in the snippet is quite simple:

#...
plans_by_supplier.each do |supplier, lines|
  vendor = lookup("Supplier Vendor Table", site: supplier)["vendor"] 
  # ... other stuff here 
  plans << {
    vendor: vendor
  }
end 

#...


At the end of the day what I'm trying to do is be able to find the value associated to a given key and return that field for each key in an array.
I know it can be done in a regular formula, but that would require looping through multiple layers of arrays to get to the fields I want, resulting in 100s of tasks. 

I'm happy to hear other suggestions to solve my issue, or any context for if this should work, if it would work with data_tables instead.. etc? 

4 REPLIES 4

gary1
Star Chef I
Star Chef I

I think there are three different Ruby gems used in Workato:

  1. Formula Ruby gem, works with lookup table
  2. SDK Ruby gem, also works with lookup table
  3. Snippet Ruby gem, doesn't work with lookup table

My recommendation is to get your entire lookup table in a previous action and pass it into Ruby snippet as input. This won't work if the LUT is over 10k rows.

If this is simply mapping problem, you may not need to use the Ruby snippet at all. It may be possible to get the keys you need without looping, but I would need to see the payload structure to know for sure.

HI @gary1 ,
How you know all this information (Gems), I'm a bit curious :), are these mentioned in the doc?

I don't know with 100% certainty, but I feel it's fair to assume...

This page mentions the SDK gem, which no longer has any whitelist:

https://docs.workato.com/en/developing-connectors/sdk/sdk-reference/whitelist-removal.html#key-capab...

The page below is for connector documentation and mentions a whitelist for the Ruby connector, but the link to the SDK implies the whitelist was removed. This is inaccurate because the Ruby connector does still have a whitelist and behaves differently from the SDK.

https://docs.workato.com/en/connectors/ruby-snippets-by-workato.html#runtime-version

And lastly, formula mode obviously has a whitelist, which is loosely mentioned here:

https://docs.workato.com/en/formulas/formula-mode.html 

  • Ruby methods not found in Workato documentation are not allowlisted and, therefore, not supported. Contact your Customer Success Manager to request new formulas for the allowlist.

Because all three of them behave differently, I can only assume they are driven by three unique gems!

Oh Okay, got it.
Appreciate your effort for sharing the detailed info....will look into these 😄.