ALTERYX INSPIRE | Join us this May for for a multi-day virtual analytics + data science experience like no other! Register Now

Dev Space

Customize & extend the power of Alteryx. SDKs, APIs, custom tools, and more!
SOLVED

How can I pre-define output fields

giang_hoang7667
5 - Atom

Hello everyone,

I'm building a custom tool with Python SDK and I'm having a problem when connecting it to other tools that have FieldSelector field (for example Text to columns tool. Where you can select the Column to split by connecting its input with another tool's output, and you can select which field contains the data to split).

Right now I need to run the workflow for the first time in order to list out the output fields of my custom tool. But in a large workflow, this became annoying.

Where can I define the output fields for my custom tool? Is it in the XML file or inside the python file?

I saw there's a function named pi_add_outgoing_connection, is that where I can use it to define the output fields?

 

 

tlarsen7572
11 - Bolide

Are you initializing your output anchor?

 

Link to docs

 

The basic process looks something like this:

 

1. During your plugin's pi_init method, get the output anchor

2a. If your tool is an input tool, initialize the output in pi_push_all_records

2b. If your tool accepts incoming data, initialize the output during (one of) the incoming connection's ii_init methods

 

An input tool might look something like this:

class AyxPlugin:
    def __init__(self, n_tool_id: int, alteryx_engine: object, output_anchor_mgr: object):
        self.output_anchor_mgr: Sdk.OutputAnchorManager = output_anchor_mgr
        self.Output: Sdk.OutputAnchor = None

    def pi_init(self, str_xml: str):
        self.Output = self.output_anchor_mgr.get_output_anchor('Output')

    def pi_push_all_records(self, n_record_limit: int) -> bool:
        # Some code to generate your recordinfo
        self.Output.init(record_info)
        # Rest of code to push data to your output anchor

 

A tool that accepts incoming connections might look like this:

class AyxPlugin:
    def __init__(self, n_tool_id: int, alteryx_engine: object, output_anchor_mgr: object):
        self.output_anchor_mgr: Sdk.OutputAnchorManager = output_anchor_mgr
        self.Output: Sdk.OutputAnchor = None

    def pi_init(self, str_xml: str):
        self.Output = self.output_anchor_mgr.get_output_anchor('Output')

    def pi_add_incoming_connection(self, str_type: str, str_name: str) -> object:
        return IncomingInterface(self)


class IncomingInterface:
    def __init__(self, parent: AyxPlugin):
        self.parent = parent

    def ii_init(self, record_info_in: object) -> bool:
        # Some code to generate your outgoing recordinfo based on incoming fields
        self.parent.Output.init(record_info_out)
        # The rest of your init code

 

Basically, the init method causes the SDK to send a message to Alteryx that allows connected tools to receive a preview of the data structure you are sending.  This allows tools with FieldSelectors or Select tool functionality to fill in their interfaces with the incoming field info. 

giang_hoang7667
5 - Atom

Oh, I get it now. I was initing the output anchor after validating the tool is UpdateOnly or not. That's why it needs to run 1 time before showing the output fields.

Thank you