mindbody api post CustomClientFields - mindbody

Im using the API class from Mindbody GetClientServices to access the MindBody Api. Works great.
Now i need to add custom values to the client defined in the Mindbody CMS (ie exmployer)
So this is the array i am using:
array('UpdateAction'=>'Update',
'Clients'=>array(
'Client'=>array(
'ID'=>'100015637',
'FirstName'=>'dummy'.$i,
'LastName'=>'Galaxy'.$i,
'BirthDate'=>'2010-05-24T18:13:00', //https://stackoverflow.com/questions/2899332/not-a-valid-allxsd-value
'Username'=> 'helloDummy1'.$i,
'Password'=> 'amin1216$1'.$i,
'Email'=>'dummy'.$i.'#noblestreet.eu',
'EmailOptIn'=> new SoapVar('true', XSD_STRING, 'xsd:boolean'),
'SendEmail'=> new SoapVar('true', XSD_STRING, 'xsd:boolean'),
'MobilePhone'=>'9770534045',
'HomePhone'=>'9770534045',
'WorkPhone'=>'9770534045',
'Address'=>'dummy'.$i,
'Address2'=>'dummy'.$i,
'City'=>'dummy'.$i,
'State'=>'ZH',
'Country'=>'NL',
'PostalCode'=>'2511HA',
'ForeignZip'=>'2511HA',
'Bio'=>'dummy'.$i,
'Status'=>'active',
'CustomClientFields' => array(
'CustomClientField'=> array(
0 => array(
'ID' => '1',
'value'=>'test'
)
)
)
)
)
);
On posting this to the API the customfield doesnt get added and i cant see it in the MB cms.
Any help on this one?
btw inserting/updating other values works

The comment made by Yuga was the correct answer:
1) Post resulting XML request you're sending to Mindbody API.
2) Try comparing your XML to the example XML updating custom fields shown on https://developers.mindbodyonline.com/Develop/ClientService.
3) Which XML response do you get? You may get an error, I suppose.
4) Most probably you need to send 'Value' not 'value'.
5) Make sure you send <Fields><string>Clients.CustomClientFields</string></Fields> in your XML request
Point 4 (correcting the typo value to Value) solved my problem.

For me we need to provide additional information like the below.
CustomclientFields
ID
DataType
Name
Value
Here is the example
'CustomClientFields' => array( 'CustomClientField'=> array(
0 => array('ID' => 1, 'DataType' => 'Number', 'Name' => 'txtCustom1', 'Value'=>121212121212, ),
1 => array('ID' => 2, 'DataType' => 'Number', 'Name' => 'txtCustom2', 'Value'=>121212, ),
2 => array('ID' => 3, 'DataType' => 'Text', 'Name' => 'txtCustom3', 'Value'=>Sampletext, ) )

Related

Existence of posts from complex WP_Query

I have a comparative set of arguments for WP_Query involving a custom field.
On a page I need to say "Are there going to be results?, if so display a link to another page that displays these results, if not ignore" There are between 500 and 1200 posts of this type but could be more in the future. Is there a more efficient or direct way of returning a yes/no to this query?
$args = array(
'post_type' => 'product',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'partner',
'value' => $partner,
'compare' => 'LIKE',
),
),
);
$partner_query = new WP_Query($args);
if ($partner_query->have_posts() ) { [MAKE LINK] }
The link is not made from data returned, we already have that information.
Perhaps directly in the database. My SQL is not up to phrasing the query which in English is SELECT * from wp_posts WHERE post_type = 'product'} AND (JOIN??) post_meta meta_key =
partner AND post_id = a post_id that matches the first part of the query.
And if I did this, would this be more efficient that the WP_Query method?
Use 'posts_per_page' => 1 and add 'no_found_rows' => true and 'fields' => 'ids'. This will return the ID of a matching post, and at the same time avoid the overhead of counting all the matching posts and fetching the entire post contents. Getting just one matching post id is far less work than counting the matching posts. And it's all you need.
Like this:
$args = array(
'post_type' => 'product',
'posts_per_page' => 1,
'no_found_rows' => true,
'fields' => 'ids',
'meta_query' => array(
array(
'key' => 'partner',
'value' => $partner,
'compare' => 'LIKE',
),
),
);
$partner_query = new WP_Query($args);
if ($partner_query->have_posts() ) { [MAKE LINK] }
no_found_rows means "don't count the found rows", not "don't return any found rows". It's only in the code, not the documentation. Sigh.

Update Post status when post is expire

I want to update post status when a post is expiring.
I have saved expiry date in the WordPress post meta (post_price_plan_expiration_date).
I know how to get an expired post with wp_query,
But I want to use SQL query to update post status.
$todayDate = strtotime(date('m/d/Y h:i:s'));
$args = array(
'post_type' => 'post',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'featured_post',
'value' => '1',
'compare' => '=='
),
array(
'key' => 'post_price_plan_expiration_date',
'value' => $todayDate,
'compare' => '<='
),
)
);
$wp_query = new WP_Query($args);
print_r($wp_query);
This code returns me correct posts which I need, But I need to write the same query in SQL, And run that with wp_schedule_event
Any help???
You can always do the following out of a WP_Query
$wp_query = new WP_Query( $args );
echo $results->request;
Which should display the generated SQL Query.
Hope this helps.

Sorting in yii 1.1

I have question regarding yii 1.1 sort.
I have three tables ticket, repairLogs and part table .
Following relations have been defined in Ticket model.
'repairLogs' => array(self::HAS_MANY, 'RepairLog', 'ticket_id', 'order'=>'ts DESC'),
and in repairLogs Table
'part' => array(self::BELONGS_TO, 'Part', 'part_id'),
Part table has a column 'number' and I want to sort the data based on "number". Can anyone guide me how to do this since I am new to the yii 1.1 framework.
You can do this during the find()
Ticket::model()->with(array('part', 'repairLogs'))->findAll(
array(
// your conditions here
'order' => 'part.number DESC', // "part" is the alias defined in your relation array (in the Ticket model file)
'limit' => 10,
)
);
If you are using A dataProvider, you can set it as a default order:
new CActiveDataProvider('Ticket', array(
'criteria' => $criteria, // you criteria that should include the "with" part
'sort' => array(
'defaultOrder' => 'part.number DESC',
)
));

Remove empty option from listData at CGridView filter

I would like to remove the empty or first option of list data value.
I have Bankaccount model and it has a list, so I need to prevent from users to select all.
I already selected the first one of that list as a default, but now the problem is the empty option that can let user to select all Bankaccount still exist, so how can I remove.
This is my code
array(
'name' => 'bank_account_id',
'type' => 'raw',
'value' => '$data->bankaccount->BankAccountName',
'filter' => Chtml::listData(Bankaccount::model()->findAll(array('order' => 'name DESC')), "id", "BankAccountName"),
),
If you look at this method that generates filter, you will see that it always adds empty option when it gets an array on input. So, the only way to hide empty option is to generate selectbox manually:
'filter' => CHtml::activeDropDownList(Bank::model(), 'bank_account_id',
Chtml::listData(Bankaccount::model()->findAll(array('order' => 'name DESC')), "id", "BankAccountName"),
),
),
Using CHtml::activeDropDownList will give you Bank[bank_account_id] in the selectbox name.
for the filter part,
'filter' => Chtml::dropdownList('Bank[bank_account_id]' , 'selectedDefault',
Chtml::listData(Bankaccount::model()->findAll(array('order' => 'name DESC')), "id", "BankAccountName"),
),
),

SugarCRM - Add leads with auto-incremented ID

I use the SOAP API to add new leads to SugarCRM. Additionally, I use a plugin to assign an auto-incremented lead ID whenever a new lead is created (http://www.sugarforge.org/projects/autoincrement/).
Now, the plugin works fine, if I create a new lead via frontend. But, if I use the SOAP API, the function from the module, which assigns the auto-increment ID to the lead, does not trigger.
I create the lead via
$module = 'Leads';
$params = array(
'session' => $session,
'module_name' => $module,
'name_value_list' => array(
array('name' => 'id', 'value' => ''),
//array('name' => 'int_lead_id_c', 'value' => ''),
array('name' => 'first_name', 'value' => $_POST["first_name"]),
array('name' => 'last_name', 'value' => $_POST["last_name"]),
array('name' => 'phone_home', 'value' => $_POST["phone"]),
array('name' => 'email1', 'value' => $_POST["email"]),
array('name' => 'assigned_user_id', 'value' => '1'),
)
);
//Create the Lead record
$lead_result = $soapclient->call('set_entry', $params);
The function in the module is this one:
class SugarFieldAutoincrement extends SugarFieldBase {
/**
* Override the SugarFieldBase::save() function to implement the logic to get the next autoincrement value
* and format the saved value based on the attributes defined for the field.
*
* #param SugarBean bean - the bean performing the save
* #param array params - an array of paramester relevant to the save, most likely will be $_REQUEST
* #param string field - the name of the field
*/
public function save(&$bean, $params, $field, $properties, $prefix = '') {
}
}
How can I make sure, that this function is also triggered, when adding leads via SOAP API?
Thanks a lot for your help! :-)
David
You would need to set the field type to 'autoincrement' and the dbType to 'int' in the vardef record for the field.
If I'm not mistaken, the Database has a UUID() trigger on insert for most tables, so you should be able to completely remove the id field.
If you want to trigger the function before saving, you can use beforeSave logic hook.