I have problem similar to this one.

I want assign node to section while being created. During php node creation I use:


which should assign node to certain section, but after script execution I see "Section: Unassigned".

When I do separately:

$node = node_load(823);

..it works. Section gets assigned. As I read Workbench access there might be some bugs preventing this from working (comments like "// Workbench Moderation submits the node twice???" and deleting of redundant nodes?)..

If it was matter of 1 node I would drop it and use second code.. But it seems like I need hundrets of nodes to be created at once so I'd rather avoid loading and saving node only for section assignment.

2 Answers 2


Where are you doing the call to workbench? Have you tried doing the call in the postprocess of the node creation. Maybe you don't have the proper database object yet when you do it?

  • I don't call workbench function. During node creation I just want to fill the field "workbench_access" to proper node id. Do you think the node needs to be created first and then modified (assigned to section) ? That's strange, as every field can be modified during node creation, before submitting...
    – wtk
    Jan 11, 2012 at 16:13
  • ok, my error. I think what is happening is that your variable is not being written. First you have to check how other variables are written, if you had this in a form the variable value is normaly written somewhere like node->variable['#value'][0]['und'] = 'value'; If this is not the case you should check where you are making this call. Sometimes you are filling the variables under form and not form_state which might be the problem or you are simply doing this before the variables that are to be written are placed. What is your wrapping function there?
    – reptilex
    Jan 11, 2012 at 16:42
  • I'm successfully writing other fields of node, so this one shouldn't be problem neither. Moreover when I separately load and save any node, this way of changing section works. Then I don't believe that problem lies in what you say.
    – wtk
    Jan 11, 2012 at 17:12
  • It would be helpful if you would give away how and in which function you are setting that variable.
    – reptilex
    Jan 13, 2012 at 9:37
  • I have written a module, which I use to remote node creation. So after function that creates node, I just use the 3 lines I pasted before. This must be done after node save. Otherwise as I stated (reason of this topic) it won't work. Should I tell you more?
    – wtk
    Jan 13, 2012 at 10:32

I ended up with my own function that refreshes possible sections. So after I create item in menu - a lot of items - then i just run this, and new sections are available:

function update_workbench_sections($menu_name="example1") {

$wanted = array();
$records = db_query("SELECT mlid FROM {menu_links} WHERE menu_name=:menu_name", 
                        array( "menu_name"=>$menu_name))->fetchAll();

foreach($records as $w) {
    array_push($wanted, $w->mlid);  

$access_scheme = db_query("SELECT * FROM {workbench_access}")->fetchAll();
$existing = array();
foreach($access_scheme as $item) {
    if( intval($item->access_id)>0 && $item->access_type_id==$menu_name ) {
        array_push($existing, $item->access_id);        

$missing = array_diff($wanted, $existing);
$values_to_insert = array();

foreach($missing as $item) {
    array_push($values_to_insert, array( "access_id" => $item, "access_type" => "menu", "access_scheme" => "menu",
                "access_type_id" => $menu_name ));  

if(count($values_to_insert)>0) {
    $query = db_insert("workbench_access")->fields( array('access_id', 'access_type', 'access_scheme', 'access_type_id'));
    foreach($values_to_insert as $value) {
return count($values_to_insert);    

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.