The most efficient way to do that in Revo is in a plugin attached to OnDocFormSave. You can get the templateVarResource objects directly, do your magic and save the appropriate TVR.
A modTemplateVarResource object has three fields.
- tmplvarid (ID of the TV)
- contentid (ID of the resource)
- value (Value of the TV for that resource)
In a plugin attached to OnDocFormSave, get each of the three TVRs like this:
<?php
$tvId = 12;
/* $id will be the resource ID */
$tv1 = $modx->getObject('modTemplateVarResource',array ('tmplvarid'=>$tvId,'contentid' = $id));
$val = $tv1->getValue();
Once you have the value for all three, set the value for the TV you want to change and save it (let's say it's $tv3 and the value you want to save there is in $newValue):
<?php
$tv3->set('value', $newValue);
$tv3->save();
And you're done. No need to mess with the resource object or the TV object at all.
FYI, Plugins with syntax errors will often just hang -- so it really helps to have a good code editor like NetBeans, PhpEd, or PhpStorm that highlights syntax errors. When a plugin hangs, you can paste the code into the code editor and look for errors.
[ed. note: BobRay last edited this post 12 years, 6 months ago.]