cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Error calculating input for field 'fieldName': no implicit conversion of nil into String

snm
Deputy Chef II
Deputy Chef II

I'm troubleshooting a job failure with the error: Error calculating input for field 'fieldName': no implicit conversion of nil into String.
I understand that the likely cause of this error is due to a + operation trying to act on a nil value from the input data. And the use of .present? or .presence could help mitigate the problem. But I am not sure how to factor that into the formula:

snm_0-1703778263924.png

Any help or guidance would really be appreciated. Thank you!

 

2 ACCEPTED SOLUTIONS

gary1
Executive Chef II
Executive Chef II

The error message you provided doesn't appear to pertain to the screenshot/formula. "fieldName" is not present in the formula. I'm guessing that the output of "Business Unit Ref ID" is being added in "fieldName" elsewhere. What does that formula look like?

In your response above to dcornwell, you mention a new error: "Error calculating input for field 'BusinessUnitRefID': no method 'where' for true". This is interesting because it appears that the value for "Custom fields" is expected to be an array of objects, but is arriving as a boolean (and you can't .where a boolean).

Without knowing more, I could only classify this as "very odd" and I recommend looking at the input data first. If the input data is arriving in an unexpected format, that may be the root cause of the formula backfiring. Once you confirm the input data is correct, read on for a suggestion on fixing the issue.

When any of the where methods return no results, you'll hit an error. This is because the other methods used to transform the result (upcase, '+', split, gsub) are string methods that will not work on nil data types. 

If you really want to retain the formula as is without rewriting it into a Ruby snippet or multiple actions, I recommend first checking for the value before transforming it like this:

 

 

## test to see if a result is present without transforming
(([Custom Fields].where("Name": "xxx").pluck('Value').first.present? : 

## now transform and test each case in a callback hell of nested ternary operators

   (([Custom Fields].where("Name": "xxx").pluck('Value').first.upcase.include?("xxx") ? 
   "result when true" : 

      ## next ternary operator here
      {test condition} ? {true result} : 

         ## next ternary operator here
         {test condition} ? {true result} : 
   
   ## ... and so on until the end of time

 

Edit: I should also mention that if the .where("Name": "xxx") is always testing for the same name "xxx", you can check for presence once at the beginning of the formula. However, if the formula checks for multiple names throughout the formula (I can't tell, they are blurred), then you'll need to test for presence each time (for each name) at the start of a new nested ternary operator. I'm getting dizzy just thinking about it!

View solution in original post

marlon-muela
Workato employee
Workato employee

Hi @snm ,

One possible reason you are getting an error is that the data pill used has an empty value.

The error indicates that it was unable to move forward with the conversion/formula is because the value is empty of doesn't match the data type being used in the formula.

Check if step 3 has a value on the job output. One suggestion for troubleshooting is to try using a static value to see if the error reproduces.

View solution in original post

6 REPLIES 6

dcornwell
Deputy Chef III
Deputy Chef III

As a side note, without seeing the whole recipe I wonder if this complex formula is the best way to go.  It seems like you're dealing with a lot of things in one formula and perhaps it could be done more dynamically through adding some other steps or even custom ruby code. 

Assuming it is best to keep it this way (or either way) I would look at adding the Safe Navigation Operator right at the beginning after the Custom Fields data pill. https://docs.workato.com/formulas/conditions.html#safe-navigation-operator 

snm
Deputy Chef II
Deputy Chef II

Thank you for your response! I am not the owner of the recipe and therefore cannot make any changes on my own. The custom fields data pill is actually a list and I tried adding the safe navigation operator but it still threw an error.

This time: Error calculating input for field 'BusinessUnitRefID': no method 'where' for true

gary1
Executive Chef II
Executive Chef II

The error message you provided doesn't appear to pertain to the screenshot/formula. "fieldName" is not present in the formula. I'm guessing that the output of "Business Unit Ref ID" is being added in "fieldName" elsewhere. What does that formula look like?

In your response above to dcornwell, you mention a new error: "Error calculating input for field 'BusinessUnitRefID': no method 'where' for true". This is interesting because it appears that the value for "Custom fields" is expected to be an array of objects, but is arriving as a boolean (and you can't .where a boolean).

Without knowing more, I could only classify this as "very odd" and I recommend looking at the input data first. If the input data is arriving in an unexpected format, that may be the root cause of the formula backfiring. Once you confirm the input data is correct, read on for a suggestion on fixing the issue.

When any of the where methods return no results, you'll hit an error. This is because the other methods used to transform the result (upcase, '+', split, gsub) are string methods that will not work on nil data types. 

If you really want to retain the formula as is without rewriting it into a Ruby snippet or multiple actions, I recommend first checking for the value before transforming it like this:

 

 

## test to see if a result is present without transforming
(([Custom Fields].where("Name": "xxx").pluck('Value').first.present? : 

## now transform and test each case in a callback hell of nested ternary operators

   (([Custom Fields].where("Name": "xxx").pluck('Value').first.upcase.include?("xxx") ? 
   "result when true" : 

      ## next ternary operator here
      {test condition} ? {true result} : 

         ## next ternary operator here
         {test condition} ? {true result} : 
   
   ## ... and so on until the end of time

 

Edit: I should also mention that if the .where("Name": "xxx") is always testing for the same name "xxx", you can check for presence once at the beginning of the formula. However, if the formula checks for multiple names throughout the formula (I can't tell, they are blurred), then you'll need to test for presence each time (for each name) at the start of a new nested ternary operator. I'm getting dizzy just thinking about it!

snm
Deputy Chef II
Deputy Chef II

Thanks for your response, gary1. BusinessUnitRefID is the field that this formula is populating. I mistakenly typed 'fieldName' in my initial post where it is meant to be 'BusinessUnitRefID'. So the error would read: Error calculating input for field 'BusinessUnitRefID': no implicit conversion of nil into String.

And you're right about Custom Fields, it is an array of objects. I'll attempt your suggested approach. Thank you once again.