Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Node does not update on CustomDataHandler View modes: 
User avatar
Member
Member
Leandro Brito - 1/11/2012 7:33:06 AM
   
Node does not update on CustomDataHandler
Hello,

I'm trying update a node programmatically but the node does not save the value.

My code snippet:



//In the OnAfterInsert() I get the node using selectsinglenode(nodeid), so I create a url //using NodeAlias.

//url example
string url = "http://www.test.com/" + node.NodeAlias + ".aspx";

node.SetValue("FieldUrl", url);
node.Update();



When I put the breakpoint on line node.Update(), the ItemArray shows the value for the collumn but doesn't save the value with the Update() method.

Can someone help me?
Thanks!

Best regards.
Leandro Brito

User avatar
Member
Member
kentico_michal - 1/11/2012 9:12:11 AM
   
RE:Node does not update on CustomDataHandler
Hello,

Well, there should not be any problem with updating the node in the OnAfterInsert handler. Could you please post here the complete code?

Also, could you please check the Event log [Site manager -> Administration -> Event log], if there is any log related to this issue?

Moroever, are you using the latest hotfix?

Best regards,
Michal Legen

User avatar
Member
Member
Leandro Brito - 1/11/2012 9:50:33 AM
   
RE:Node does not update on CustomDataHandler
My code snippet:



public override void OnAfterInsert(object dataObj, object conn)
{
SimpleDataClass dataItem = dataObj as SimpleDataClass;
if (dataItem != null)
{
if (dataItem.ClassName.ToLower() == "cms.document")
{
CMS.SiteProvider.UserInfo ui = CMS.SiteProvider.UserInfoProvider.GetUserInfo("administrator");
CMS.TreeEngine.TreeProvider tree = new CMS.TreeEngine.TreeProvider(ui);

int documentId = CMS.GlobalHelper.ValidationHelper.GetInteger((dataObj as SimpleDataClass).GetValue("DocumentID"), 0);
CMS.TreeEngine.TreeNode node = tree.SelectSingleDocument(documentId);
if (node != null)
{
string urlBairro = string.Empty;

if (node.NodeClassName.ToLower() == "custom.bairros")
{
//node = tree.SelectSingleNode(CMSContext.CurrentSite.SiteName, node.NodeAliasPath, TreeProvider.ALL_CULTURES);
string parametrosBusca = node.GetValue("BairrosParametroBusca").ToString();

string cidade_estado = Util.GerarUrlDocumentBairro(parametrosBusca);

if (!string.IsNullOrEmpty(cidade_estado))
{
string newAliasPath = string.Format("/{0}/{1}", cidade_estado, node.NodeAlias.ToLower());
newAliasPath = Util.RemoveAccentsWithRegEx(newAliasPath);

CMS.TreeEngine.DocumentAliasInfo aliasinfo = new CMS.TreeEngine.DocumentAliasInfo();
aliasinfo.AliasURLPath = newAliasPath;
aliasinfo.AliasSiteID = CMS.CMSHelper.CMSContext.CurrentSiteID;
aliasinfo.AliasNodeID = node.NodeID;
aliasinfo.AliasExtensions = ".aspx";
aliasinfo.SetObject();

//Here is the update of node
node.SetValue("UrlBairro", newAliasPath);
node.Update();
}
}
}
}
}
}



The event log is clear, it has only information about the process, withous errors.

I'm not using the hotfix.

Thanks

User avatar
Member
Member
kentico_michal - 1/12/2012 8:17:45 AM
   
RE:Node does not update on CustomDataHandler
Hello,

Could you please debug the this code and make sure that the node.Update() method gets executed.

Do you use also some custom code in the CustomTreeNodeHandler class, for example in the OnBeforeUpdate method that could eventually stop updating the document.

Could you please also apply the latest hotfix fo your current version of Kentico CMS?

Best regards,
Michal Legen