2

I want to prefill a webform with data from a specific CiviCRM activity in order to edit the activity using the webform. I want to do this by having an "Edit" link in a Drupal View of CiviCRM activities. These activities may or may not be associated with a case, so let's assume they aren't. I've turned on "Update Existing Activity" in the webform for all of the statuses.

Can someone confirm that I can do this, and if so, what is the proper form of the URL for the link in the view? I've tried a bunch of different ones and can't seem to get it.

3
  • What about VBO to modify a field ? Commented Oct 1, 2019 at 20:54
  • For Bulk operations - absolutley. But it’s a lot of overhead to update a single activity. Commented Oct 1, 2019 at 21:20
  • Guy: did you have a chance to review the screenshots I posted? Let me know of there is anything else I can add to help you make this work. Commented Oct 8, 2019 at 13:20

3 Answers 3

7

Below please find some screenshots to illustrate how to do this:

1. This is a View of Activities. Each Activity has an Update button [that's a Global: Custom Text field -> Text Update; Rewrite results: Output this field as a link -> to the webform URL with case-worker-form?cid2=[contact_id]&aid=[id] and bootstrap classes btn to make it a button] -> the URL that is constructed is case-worker-form?cid2=41218&aid=19153

enter image description here

2. The webform case-worker-form -> receives this data. That form is set up such that cid1 = the logged in user (the social worker); cid2 = the client; aid = activity id of the activity to be updated;

enter image description here

3. Let's edit the subject e.g. ->

enter image description here

4. Result:

enter image description here

5. Note the Webform just has Update Existing Activity set to None (as we're matching by aid) enter image description here

Add on: I've double checked that this is (still) working on our latest webform civicrm 5.x

root@f4d0afb6c36d:/var/www/html/sites/default/modules/webform_civicrm# git log
commit 76b444bf5192ddf4663a0222540684a230d8e39e
Merge: b54ddfd ef2a518
Author: Karin Gerritsen <KarinG>
Date:   Thu Sep 12 11:24:26 2019 -0600
    Merge pull request #251 from colemanw/rel7
    Use api to retrieve relationship data

Add - on config notes:

  • ensure your views field is configured such that commas are stripped from cid and aid before passing them into the webform

  • ensure your webform is configured to allow an activity of the type you want updated -> setting it to -user select- will ensure that

2
  • I figured out why mine wasn't working. Seems obvious now, but I missed it. On ANY contact field that you are sending the info for in the URL, you have to check the "Use contact id from URL" checkbox under "Default value" for that webform field. If any of the contact fields that you sending the value for do not have that box checked, none of the form will load. So the final form of the URL I used was yourdomain/yourwebform?cid2=xxx&aid=xxx&cid1=xx. Thanks for the help.
    – guyiac
    Commented Nov 19, 2019 at 20:52
  • Yes passing cid via arguments does require the Contact Element to be configured as such. Happy to hear you got things working. Commented Nov 19, 2019 at 22:06
2

Having "Update Existing Activity" setting turned on, prefills the form with the matching activity based on Type and Status. In case of multiple activities, it prefills/updates the first one.

Adding '&activity1=activityID' in your webform url, irrespective of the 'Update Existing Activity' setting, will prefill and update the activity (with id=activityID).

In case of revisioning you might need to provide latest activity ID in url or it might not work. Think you could have some custom code or configuration in view to fetch the latest activity id for a contact, to make it work.

0

This should work but is a bug in the latest version of Webform CiviCRM. Will open a ticket. (Update) Webform requires that the form is configured a certain way on the civicrm tab for activities in order to load the activity. It appears that at least 1 contact on the form needs to be set as a participant on the webform for the autoload to work. nb. I'm going to investigate further if other combinations will or will not work.

9
  • I think this is right. I've tried all the iterations for the URL and I can't get it to work.
    – guyiac
    Commented Oct 1, 2019 at 14:19
  • If you think there is a bug please do let us know - we've got this working on a number of sites though; URLs in this format: case-worker-form?cid2=41218&aid=19153 work fine as long as the receiving webform is configured properly. Commented Oct 1, 2019 at 15:27
  • I just ran a test with our webform civicrm 5.x latest - commit 76b444bf5192ddf4663a0222540684a230d8e39e Merge: b54ddfd ef2a518 Author: Karin Gerritsen <[email protected]> Date: Thu Sep 12 11:24:26 2019 -0600 Merge pull request #251 from colemanw/rel7 - and all is working well. Will add screenshots to my answer. Commented Oct 1, 2019 at 15:51
  • Jamie: can you please either open an issue with details on how to reproduce or acknowledge there is no bug - that passing on aid in URL works as described by me in both 4.x and 5.x? Commented Oct 3, 2019 at 12:10
  • Hi @karinG-SemberIT - Sorry ran out of time last week. I've done some more investigating and it seems that the activity ID is loaded but only in certain scenarios where the source/target/assignee fields are being set by the form. There may also be a bug with the "none" option. In your example above you set the activity participants to be contacts on the form. Commented Oct 5, 2019 at 11:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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