How do I programmatically update an existing submitted webform submission in Drupal? I am attempting to use PHP in Drupal rules to update the values in submitted webform submissions. I can access and view the data correctly. When I assign a new value to a field it will even show up correctly if I use print $submission->data[61][0]; But when I navigate to the submission results page the field hasn't been updated.

I have tried using the webform_submission_update() function to push my change but still no luck.

Question: How do I programmatically update an existing submitted webform submission in Drupal?

Code: 

$submission = webform_menu_submission_load($nid, $sid);

// Two ways I've tried to update the data
$submission-&gt;data[61][0] = "testwork";
$submission-&gt;data[61]['value'][0] = 'Declined';

// If I do print $submission-&gt;data[61][0]; it will show the new value.

webform_submission_update($nid, $submission);
Here's how to do that:

// Load the webform submissions file. The webform_get_submission() and
// webform_submission_update() functions are located here.
module_load_include('inc', 'webform', 'includes/webform.submissions');

// Load the node and submission.
$node = node_load(YOUR_NODE_ID);
$submission = webform_get_submission($node-&gt;nid, YOUR_SUBMISSION_ID);

// Change submission data.
//
// To see what's available, install Devel and run dpm($submission);
$submission-&gt;data[YOUR_FORM_ELEMENT_ID][0] = 'Update';

// Finally, update the submission.
webform_submission_update($node, $submission);


Documentation:


webform_get_submission()
webform_submission_update()