Can I concatenate parameters in Action forms?

I have an action to Create an object and I want to auto-populate the Title parameter as a concatenation of some of the other parameters.

eg. Client Name = Toy Company Ltd
Target = New Revenue
Amount = $10,0000

and I want the title to be:
Title = New Revenue for Toy Company Ltd

so Target + " for " + Client Name
This used to be possible in Foundry Forms, but I can’t figure out how to make parameters in the Action form be a function of other parameters.

Are there any ways to do this? or other suggestions for how to auto-create a reasonable Title property automatically? Could it be done on the Workshop side instead?

Hey!

I think the most straightforward way to achieve that functionality is by creating a variable and using that to configure the parameter on action form within the Workshop.

If you go to Variables → New → String → Variable Transformation → String Concatenation you can concat the ClientName and the Target variable, and then use the resulting value for the Action form.

Hope that helps!

Hi! There isn’t a first class way to do this currently but here are two ways that you can get around this issue.

  1. Using Workshop Variables: Store your object parameters as Workshop variables and then use an additional workshop variable that concats the two with your desired delimiter (“for”). In this instance you would need to create a form as parameters applied to action forms are not directly accessible to Workshop.

  2. Switching to a function-backed action: This gives you the freedom to engage with the parameters provided however you wish. In this case, Client Name and Target would be two parameters that you can then write to your object property title like so.

@OntologyEditFunction
async createNewObject(clientName:string, target: string, amount, integer):Promise<void>{
  const title = clientName.concat(" for ", target);
  const object = Objects.create().object();
  object.title = title;
  object.clientName = clientName;
  object.target = target;
  object.amount = amount;
  ...
  //rest of properties defined here.
}

Hi @theo_bell

The cleanest way is to keep using action forms and manage the complexity using a function-backed action:

If you replace with your object type names in the following code, it should work by coping and pasting:

import { Double} from "@foundry/functions-api";
import { YourObjectType } from "@foundry/ontology-api"
import { Uuid } from "@foundry/functions-utils";

@Edits(YourObjectType)
@OntologyEditFunction()
public createYourObjectType(target: string, clientName: string, amount: Double): Promise<void>  {
	const foo = Objects.create().yourObjectType(Uuid.random());
	foo.target = target;
	foo.clientName = clientName; 
	foo.amount = amount; 
	foo.title = "".concat(target, " for ", clientName);
	// [...] Other properties
}

PS: I assumed your amount is of Double type.

1 Like