Buy Now
Sign in

Modify Data

rtobias , April 25 2017, 21:37
R
rtobias 53
April 25 2017, 21:37 #367439
How would I use the Modify Data action?

In CF5, I would use a Custom action with php code:

<?php
$form->data['id'] = $form->data['Data2']['id'];
$form->data['eid'] = $form->data['Data2']['id'];
$form->data['email'] = $form->data['Data2']['email'];
$form->data['first_name'] = $form->data['Data2']['first_name'];
$form->data['last_name'] = $form->data['Data2']['last_name'];

$form->data['civicrm_contact_id'] = $form->data['Data2']['civicrm_contact_id'];
$form->data['created_date'] = $form->data['Data2']['created_date'];
$form->data['modified_date'] = $form->data['Data2']['modified_date'];
$form->data['ordering'] = $form->data['Data2']['ordering'];
$form->data['state'] = $form->data['Data2']['state'];
$form->data['checked_out'] = $form->data['Data2']['checked_out'];
$form->data['checked_out_time'] = $form->data['Data2']['checked_out_time'];
$form->data['created_by'] = $form->data['Data2']['created_by'];

$form->data["code"] = "";
?



I could do similar in CF6 using a PHP action in the Custom section and this code:

$this->data['id'] = $this->data['Data2']['id'];
$this->data['eid'] = $this->data['Data2']['id'];
$this->data['email'] = $this->data['Data2']['email'];
$this->data['first_name'] = $this->data['Data2']['first_name'];
$this->data['last_name'] = $this->data['Data2']['last_name'];

$this->data['civicrm_contact_id'] = $this->data['Data2']['civicrm_contact_id'];
$this->data['created_date'] = $this->data['Data2']['created_date'];
$this->data['modified_date'] = $this->data['Data2']['modified_date'];
$this->data['ordering'] = $this->data['Data2']['ordering'];
$this->data['state'] = $this->data['Data2']['state'];
$this->data['checked_out'] = $this->data['Data2']['checked_out'];
$this->data['checked_out_time'] = $this->data['Data2']['checked_out_time'];
$this->data['created_by'] = $this->data['Data2']['created_by'];

$this->data["code"] = "";


I assume the Modify Data action was included to make this easier maybe?
Randy
admin 30
April 26 2017, 18:03 #367466
Hi Randy,

Yes, in the data provider you could add: {data:Data2}, and then you could access the new data set using {var:modify_daya_fn_name}, you can use that to pass the new data set to a data save function for example.

But you may also modify the new data set using the data override, you could add this:

created_by:111

So you would get the full Data2 data but the "created_by" value would not be the same, it would be "111" instead.

Best regards,
Max
R
rtobias 53
April 26 2017, 19:09 #367468
Thanks a bunch, Max. I'll give it a try.

I think this also answers another question of mine: If we are using the line separated list of conditions for a DB action, I'm assuming we would be listing the conditions as:
field_name:value


So if I wanted to read a row as defined by a contact id I have in a url param (I use eid), I would simply use a php action named getEid:
return $_GET['eid'];


And in my DB Read action's Where section:
eid:{var:getEid}
Randy
admin 30
April 26 2017, 19:25 #367469
 Answer
Hi Randy,

That would work, but there is a shortcode for getting the request parameters directly:

{data:eid}

Best regards,
Max
R
rtobias 53
April 26 2017, 19:26 #367470
Awesome!
Randy
R
rtobias 53
April 28 2017, 18:26 #367570
Everything is still working great, but I was just wondering, what happens if you have a url param with the same name as a field? As I understand it, they would both be referenced as stated in the instructions:

{data:PARAMETER_NAME}
Get a url parameter or a form input value.

Is there a priority (like if you have a field named "eid" and a url param, also named "eid", {data:eid} returns the value of the field)?
Randy
admin 30
April 28 2017, 18:27 #367572
 Answer
Hi Randy,

Yes, the field value has priority because its in the post array.

Best regards,
Max
R
rtobias 53
April 28 2017, 18:28 #367573
Great, thanks for clarifying.
Randy