Skip to main content

Hello,

I am building a connector using the Connector SDK and have run into an issue where the call() ruby method is not available within the input_fields section of an action.

Methods Definition for set_required_fields 

  methods: {
set_required_fields: lambda do |object_definition, property_names|
property_names.each do |name|
obj = object_definition.find{ |o| oo"name"] == name }
objj"optional"] = false
end
object_definition
end
},

This method takes an object_definition and a list of properties names and updates their optional field to be false (or required) for a specific action.

Calling Method from input_field and execute blocks:

  actions: {
class_create: {
title: "Create A Class",
subtitle: "Create A Class",

input_fields: lambda do |object_definitions|
classObj = object_definitionsn"class"]
classObj = call('set_required_fields', classObj, ,"name", "lab", "sku"])
end,

output_fields: lambda do |object_definitions|
...
end,

execute: lambda do |connection, input_fields, input_schema, output_schema|
classObj = call('set_required_fields', input_schema, ,"name", "lab", "sku"])
puts classObj
...
end,
},
}

In both scenarios, I use the call() method and pass in either the object_definition or input_schema.

Result for input_field:

The following error occurs when testing my Create A Class method when attempting to use call() to invoke my method, which points to the line where call() is being invoked:

classObj = call('set_required_fields', classObj, ,"name", "lab", "sku"])

Something went wrong
undefined method `call' for #<CustomAdapter::KlassFactory::DescriptorEvalContext:0x00007f9bc1fd1ad8> at line: 197

Result for execute:

I don’t receive an error here and I see the expected output from the puts classObj command in the console when testing my method.

Takeaway

It appears the call() method is available in the execute block, but not for the input_fields block. Can anyone confirm if that is true? And if so, is there any way I could invoke my method from the input_fields block? I’m aiming to use this method to allow a helper method for easily changing which input fields are required for a shared object_definition based on the action being taken against it.

Thanks!

@jsheetsot I never used it, but take a look at the config_fileds property that allows you to control which fields are required/optional for specific actions:

https://docs.workato.com/developing-connectors/sdk/guides/config_fields.html


Hi @alekwo, appreciate the response!

I was hoping to avoid config_fields as this requires both an additional input to be configured and to select the appropriate config_field option when users build the recipe.

In  my use case, I have an object_definition shared by several CRUD actions. Some properties are required for some operations and not for others, such as:

Property GET CRATE UPDATE DELETE
id YES NO NO YES
name NO YES OPTIONAL NO
sku NO YES OPTIONAL NO

 

So far, I’ve not found a way to accomplish this without having multiple object_definitions for each case or config_fields.


I ended up using the following strategy:

  1. Create a base object_definition with all the shared properties that the different CRUD actions utilize
  2. Create a object_definition for each CRUD action that needs a unique set of required or omitted properties from the base object_definition
  3. Created methods that allow me to change the hash properties of the base object_definition in each CRUD object_definition so that I can re-use the base properties but tweak the specific ones for that action

This will allow me to re-use a majority of my base object_definition but update the specific needs for each CRUD definition with a lines of code in the connector SDK.


Reply