Answers.Body: <p>Below please find some screenshots to illustrate how to do this:</p>
  
  <p><strong>1. This is a View of Activities.</strong> 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 <code>case-worker-form?cid2=[contact_id]&amp;aid=[id]</code> and bootstrap classes btn to make it a button] -> the URL that is constructed is <code>case-worker-form?cid2=41218&amp;aid=19153</code></p>
  
  <p><a href="https://i.sstatic.net/JpvrL.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/JpvrL.png" alt="enter image description here"></a></p>
  
  <p><strong>2. The webform case-worker-form -> receives this data.</strong> 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; </p>
  
  <p><a href="https://i.sstatic.net/QIk4d.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/QIk4d.png" alt="enter image description here"></a></p>
  
  <p><strong>3. Let's edit the subject e.g. -></strong> </p>
  
  <p><a href="https://i.sstatic.net/1nAZ7.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/1nAZ7.png" alt="enter image description here"></a></p>
  
  <p><strong>4. Result:</strong></p>
  
  <p><a href="https://i.sstatic.net/ACkjx.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ACkjx.png" alt="enter image description here"></a></p>
  
  <p><strong>5. Note the Webform just has Update Existing Activity set to None</strong> (as we're matching by aid)
  <a href="https://i.sstatic.net/nmH18.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/nmH18.png" alt="enter image description here"></a></p>
  
  <p><strong>Add on:</strong>
  I've double checked that this is (still) working on our latest webform civicrm 5.x</p>
  
  <pre><code>root@f4d0afb6c36d:/var/www/html/sites/default/modules/webform_civicrm# git log
  commit 76b444bf5192ddf4663a0222540684a230d8e39e
  Merge: b54ddfd ef2a518
  Author: Karin Gerritsen &lt;KarinG&gt;
  Date:   Thu Sep 12 11:24:26 2019 -0600
      Merge pull request #251 from colemanw/rel7
      Use api to retrieve relationship data
  </code></pre>
  
  <p><strong>Add - on config notes:</strong></p>
  
  <ul>
  <li><p>ensure your views field is configured such that commas are stripped from cid and aid before passing them into the webform</p></li>
  <li><p>ensure your webform is configured to allow an activity of the type you want updated -> setting it to -user select- will ensure that</p></li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-19T20:52:57.973Z
Answers.Text: 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 https://yourdomain/yourwebform?cid2=xxx&aid=xxx&cid1=xx. Thanks for the help.
Answers.UserDisplayName: guyiac
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-19T22:06:56.327Z
Answers.Text: Yes passing cid via arguments does require the Contact Element to be configured as such. Happy to hear you got things working.
Answers.UserDisplayName: KarinG - Semper IT
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-30T20:19:54.490Z
Answers.LastActivityDate: 2019-10-01T16:37:59.453Z
Answers.LastEditDate: 2019-10-01T16:37:59.453Z
Answers.UserDisplayName: KarinG - Semper IT
Answers.Body: <p>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.</p>
  
  <p>Adding '&amp;activity1=activityID' in your webform url, irrespective of the 'Update Existing Activity' setting, will prefill and update the activity (with id=activityID).</p>
  
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-30T18:24:40.317Z
Answers.LastActivityDate: 2019-09-30T21:43:29.927Z
Answers.LastEditDate: 2019-09-30T21:43:29.927Z
Answers.UserDisplayName: Deepak Srivastava
Answers.Body: <p>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.  </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-01T14:19:38.010Z
Answers.Text: I think this is right. I've tried all the iterations for the URL and I can't get it to work.
Answers.UserDisplayName: guyiac
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-01T15:27:31.503Z
Answers.Text: 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.
Answers.UserDisplayName: KarinG - Semper IT
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-01T15:51:36.483Z
Answers.Text: I just ran a test with our webform civicrm 5.x latest - commit 76b444bf5192ddf4663a0222540684a230d8e39e
  Merge: b54ddfd ef2a518 Author: Karin Gerritsen <karin@semper-it.com>
  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.
Answers.UserDisplayName: KarinG - Semper IT
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-03T12:10:36.020Z
Answers.Text: 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?
Answers.UserDisplayName: KarinG - Semper IT
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-05T11:41:49.030Z
Answers.Text: 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.
Answers.UserDisplayName: Jamie Novick - Compucorp
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-05T11:41:52.623Z
Answers.Text: I'm going to do some more investigating to see what those precise scenarios are as my sense is that the activity should load even if you don't set these fields, as there is good reason that you may not want to change the source, assignee or with fields on the form. I'm also not sure if it works with multiple activities. Will report back in the next few days.
Answers.UserDisplayName: Jamie Novick - Compucorp
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-05T12:14:06.373Z
Answers.Text: Hi Jamie - You will need to pass on the cid2 for the Activity Target (if your webform config has a cid1 as logged in user) -> but you can then decide to disable [see my example] or hide that from the form if in your workflow target is not supposed to be edited; Assign to can be handled similarly; Re: multiple activities - we don't have a pathway for ?aid1, ?aid2 to be added as arguments. If you want to e.g. complete all activities of a certain type e.g. then best to use Views Bulk Operations.
Answers.UserDisplayName: KarinG - Semper IT
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-05T15:42:04.837Z
Answers.Text: I still don't have this working either. Just getting back to reviewing the latest notes here. Will investigate over the next few days and report.
Answers.UserDisplayName: guyiac
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-20T23:04:41.910Z
Answers.Text: Per my comment above on the main answer, double check that "Use contact id from URL" is checked for all contacts on the webform. If it isn't on even one contact field, the entire form won't load.
Answers.UserDisplayName: guyiac
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-01T14:16:27.800Z
Answers.LastActivityDate: 2019-10-05T11:43:57.597Z
Answers.LastEditDate: 2019-10-05T11:43:57.597Z
Answers.UserDisplayName: Jamie Novick - Compucorp
Body: <p>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.</p>
  
  <p>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.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-01T20:54:08.823Z
Comments.Text: What about VBO to modify a field ?
Comments.UserDisplayName: Jacques-Marie Moranne
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-01T21:20:49.570Z
Comments.Text: For Bulk operations - absolutley. But it’s a lot of overhead to update a single activity.
Comments.UserDisplayName: KarinG - Semper IT
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-08T13:20:18.347Z
Comments.Text: 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.
Comments.UserDisplayName: KarinG - Semper IT
Tags: <drupal><webform-civicrm><activities><drupal-views>
Title: Prefill webform with civicrm activity data
ThreadText: # Prefill webform with civicrm activity data
  
  (Asked by: username_0 on 2019-09-30)
  
  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.
  
  **Tags:** drupal, webform-civicrm, activities, drupal-views
  
  > **Comments:**
  > **username_1**: What about VBO to modify a field ?  
  > **username_2**: For Bulk operations - absolutley. But it’s a lot of overhead to update a single activity.  
  > **username_2**: 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.  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_2 on 2019-09-30. Score: 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
  
  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; 
  
  3. Let's edit the subject e.g. -> 
  
  4. Result:
  
  5. Note the Webform just has Update Existing Activity set to None (as we're matching by aid)
  
  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 
  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
  
  > **Comments:**
  > **username_0**: 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 https://yourdomain/yourwebform?cid2=xxx&aid=xxx&cid1=xx. Thanks for the help.  
  > **username_2**: Yes passing cid via arguments does require the Contact Element to be configured as such. Happy to hear you got things working.  
  
  ---
  
  ### Answer by username_3 on 2019-09-30. Score: 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.
  
  
  ---
  
  ### Answer by username_4 on 2019-10-01. Score: 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.
  
  > **Comments:**
  > **username_0**: I think this is right. I've tried all the iterations for the URL and I can't get it to work.  
  > **username_2**: 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.  
  > **username_2**: I just ran a test with our webform civicrm 5.x latest - commit 76b444bf5192ddf4663a0222540684a230d8e39e Merge: b54ddfd ef2a518 Author: Karin Gerritsen <karin@semper-it.com> 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.  
  > **username_2**: 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?  
  > **username_4**: 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.  
  > **username_4**: I'm going to do some more investigating to see what those precise scenarios are as my sense is that the activity should load even if you don't set these fields, as there is good reason that you may not want to change the source, assignee or with fields on the form. I'm also not sure if it works with multiple activities. Will report back in the next few days.  
  > **username_2**: Hi Jamie - You will need to pass on the cid2 for the Activity Target (if your webform config has a cid1 as logged in user) -> but you can then decide to disable [see my example] or hide that from the form if in your workflow target is not supposed to be edited; Assign to can be handled similarly; Re: multiple activities - we don't have a pathway for ?aid1, ?aid2 to be added as arguments. If you want to e.g. complete all activities of a certain type e.g. then best to use Views Bulk Operations.  
  > **username_0**: I still don't have this working either. Just getting back to reviewing the latest notes here. Will investigate over the next few days and report.  
  > **username_0**: Per my comment above on the main answer, double check that "Use contact id from URL" is checked for all contacts on the webform. If it isn't on even one contact field, the entire form won't load.  
  
  ---
  
  