1

I have a scenario where site users are able to create content in Drupal. Let's assume they will only ever create one node. Their details are in CiviCRM already since they have a Drupal user account, but I'd like to pass values from fields in the node (e.g. URL and the Title) of the node into custom fields in the node author's contact record in CiviCRM.

  • Hi David - naive question perhaps, but do you actually need to push the data in to civicrm, or would it have been enough to use CiviCRM Node Reference, and just reference the civi id on the node, and then build a View that would show you all the nodes that are related to that Contact? Otherwise it seems you are storing data in two places. – petednz - fuzion Sep 3 '16 at 9:32
  • Good question. The objective was to use the node title and path in Civimail. We also wanted to create a smart group based on the date field (all contacts with a start date from May 1 onwards). This was a quick solution that achieved what I needed relatively quickly, so I didn't go any further. – millionleaves Sep 4 '16 at 1:23
2

I got this working by installing the CiviCRM Rules and CiviCRM Entity modules in Drupal. I was then able to create a rule that would populate custom fields in the node author's CiviCRM individual contact record with values from the node when the node was created or updated. In my case, it was the node title, the node path, and a custom date field on the node.

The key was to create a rule that would trigger on node create or edit, and then update each of the CiviCRM fields I wanted. The CiviCRM fields were accessible in Rules as node:author:civicrm-contact:custom-1, node:author:civicrm-contact:custom-2 and so on.

Note the use of node:author not current:user - I wanted the node:author record to be updated. Whilst these would be the same when the author creates/updates the node, they would be different if another user updated the node. If you use current:user, then the fields of the current user would be updated. I guess there is a use case where that would be desirable, but it wasn't what I wanted.

I was then able to use Drupal's Admin Views module (which incorporates Views Bulk Operations) to carry out a bulk save on all the nodes that had been created prior to configuring this set-up - this triggered the rule and updated the individual field

The only thing I haven't solved at this point is how to allow multiple instances of my custom field set in CiviCRM (i.e. to capture the fields for multiple nodes created by the same author). I initially configured the field set this way, but found that each save of a node added a new instance of the field set in the CiviCRM contact record rather than updating the existing field set. When I reverted to a single instance, the fields were simply updated on each save.

  • I wonder if you can create a node ID field in your custom fieldset that gets set by a rule on node create, and only the other fields get set (possibly with a second rule just for node edit) on edit only if the node ID matches the field? That may stop a new instance of the fieldset being created each time, but bear in mind it's just an untested idea. – Eli Lisseck Sep 1 '16 at 14:08
  • I can see the potential for this idea. Pushing the NID across is just an extension of what I've already done ... you'd then need to create a loop in Rules to check each fieldset in turn, and update the fieldset where the NID matches... – millionleaves Sep 2 '16 at 1:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.