Creating Calculation Field with API - variable is not valid
I'm creating an App using the Podio API...
PodioApp::Create();
I then create fields in that app...
$flds = array(type => "location", config => array(label => "Address",description => "address field", delta => 1,required => true));
$fldid = PodioAppField::create($appId,$flds);
$flds = array(type => "text", config => array(label => "Test",description => "address field", delta => 3, settings => array(size=>"small"),required => true));
$fldid = PodioAppField::create($appId,$flds);
In the same script I then try and create a Calculation Field that references the "Test" field...
$flds = array(
type => "calculation",
config => array(
label => ">",
description => "Contacts Header",
delta => 2,
settings => array(script => "var a = @Test"),
required => false));
$fldid = PodioAppField::create($appId,$flds);
I then get a Fatal Error saying "The variable Test is not valid".
Not sure I understand this because I created the Test field, so why is it not able to find it for the calculation?
-
The format of variables in calculation fields is
[label](variable-identifier)
. The label is only for showing in the UI. There are a number of variable identifiers, the simplest of which isfield_X
, whereX
is a field id. So instead of@Test
you need do use@[Test](field_123)
, where123
is your field id.Hope it helps.
Best,
Andreas -
Thanks Andreas. That leads me to another question...If I'm creating the fields within the PodioApp::Create() call, how will I get the Field ID of the field I need to reference in a calculation if I'm creating all the fields in one Api call? Am I making sense?
Also, is there a reference page to where I can find all the variable identifiers?
-
I got the calculation field working perfectly now thankyou!
Not sure if I should submit a separate question, but it's kinda related so here goes...
I'm now creating a reference field in my Property App. In the Property App I'm creating a Reference field to reference a Contacts App. I'm building the API call and I have a question for what the App_Id value should look like?
$flds = array(
type => "app",
config => array(
label => "Contacts",
description => "Add new contacts here",
delta => 3,
settings => array(reference_apps => array(app_id=>$contactAppId)),
multiple => true));$contacts_id = PodioAppField::create($appId,$flds);
This Api call creates the Reference field no problem, it just doesn't reference the Contacts App. I didn't include the view_id because I really didn't know what that was or how to get it.
-
I figured it out. I just need the straight up ID value i.e. 5151121. I also have to do a better job on spelling because I've spent hours debugging code where I spelled it like "reference_apps" instead of "referenced_apps" (with the "d"). ugh! Thanks for the help Andreas. I'm sure I'll have more questions as I work through the API
Please sign in to leave a comment.
Comments
5 comments