How to programmatically set node alias on node save
Path alias could be set using the path module in the core. Just call path_save the following from a function (or hook) of your choice. In your case I'd recommend you to implement the following code in hook_node_insert, because it is called after a node has been saved, and the node will have a valid nid.

// Assuming you have a $node object already.
$path = array(
  'source' =&gt; "node/{$node-&gt;nid}",
  'alias' =&gt; $alias,  // Any alias that you want to set.
  'language' =&gt; $lang_code,  // Optional, if you are working on a multilingual site.
);
path_save($path);


If you have global redirect set, the node page will be redirected to the alias.