а

Update sets ParentID = 0 instead of NULL


#1

Hi Guys

I am using a tree with the connector & dataProcessor. Everything is working successfully when I set the RootItemRelationIDValue = 0 in the connector and update my database to have 0 as the default ParentID value. However I would prefer to use NULL as the default value. So I removed this line

connector.RootItemRelationIDValue = “0”;

in my config and updated my database to have NULL as the default ( root level ) parent id.

This worked fine and renders the tree correctly, but when updating items via the dataProcessor it sets the Parent ID to 0 instead of null

Here is the logger output :

04:13:45 PM DataRequest: Extracted values are: [ ParentSRID = 0,Description = Implement Password Change and Application Users]

TeamWrxWeb.Handlers.TreeDataHandler: DEBUG - Action - > Updated
04:13:45 PM DataRequest: Executing update action.
04:13:45 PM MSSQLAdapter: Entering: ExecuteUpdateQuery
04:13:45 PM MSSQLAdapter: Creating UpdateQuery from TableName: [wrx_Campaigns].[dbo].[ut_ServiceRequests], Fields-Values: ParentSRID = 0, Description = Implement Password Change and Application Users, Status = 478, PrimaryKeyField: ServicerequestID, PrimaryKeyValue: 172
04:13:45 PM MSSQLAdapter: Update query: UPDATE [wrx_Campaigns].[dbo].[ut_ServiceRequests] SET ParentSRID = ‘0’, Description = ‘Implement Password Change and Application Users’, Status = ‘478’ WHERE ServicerequestID = ‘172’
04:13:45 PM MSSQLAdapter: Leaving: ExecuteUpdateQuery

this executes perfectly well but when I refresh my tree this item is no longer visible as it’s parentID is now 0 and not NULL.

According to documentation “In hierarchical data structures sometimes appear the question: what value should be used for indicating the top (root) item. dhtmlxTree(Grid)Connector assumes that the root item’s ParentID value is null

I am using the .Net Connector and the latest PRO edition which I am still evaluating.

I could probably attach an event and update the value from 0 to NULL but I don’t think that would be the correct fix? Any Suggestions?

Regards

Mark


#2

Hello,
I think the only solution is to attach event and remove parent id from root items, since dataprocessor always uses 0 as default value for relation id. On the server side it may look as following

public override IdhtmlxConnector CreateConnector(HttpContext context) { dhtmlxTreeGridConnector connector = new dhtmlxTreeGridConnector(...); connector.BeforeProcessing += new EventHandler<DataActionProcessingEventArgs>(connector_BeforeDataActionProcessing); connector.RootItemRelationIDValue = "null"; return connector; } void connector_BeforeDataActionProcessing(object sender, DataActionProcessingEventArgs e) { if (e.DataAction.Data[(TableField)"item_parent_id"] == "0") { e.DataAction.Data.Remove((TableField)"item_parent_id"); } }


#3

Thanks Aliaksandr

I tried your recommendation, but tit didn’t work till i tweaked it a bit. This is what I ended up with :

if (e.DataAction.Data.ContainsKey((TableField)ParentIDColumnName) && e.DataAction.Data[(TableField)ParentIDColumnName] == “0”)
e.DataAction.Data[(TableField)ParentIDColumnName] = “null”;
});

Where ParentIDColumnName is a string naming the parent id column. This however proved to be the easy part, as there are other methods which are somewhat inconsistent in their working and users will need to be careful not to be caught out by them, for example :

To reload the tree you need to do the following

tree.deleteChildItems(0);tree.loadXML(’…/common/tree3.xml’);

notice how I had to pass in 0 as the root node, even though the default root node value should be null ( or just empty method deleteChildItems();, but i tried this and it doesn’t work )

The same applieas for refreshItem(itemId) and refreshItems(itemId, source)

Thanks for the help though

Cheers

Mark


#4

In case anyone else has this problem, I too encountered it but solved it by adding the custom SQL using a CASE (if) statement like this:

connector.Request.CustomSQLs.Add(CustomSQLType.Update, "UPDATE OrganisationUnitStructure SET ParentOrgUnitId=CASE WHEN {ParentOrgUnitId}=0 THEN NULL ELSE {ParentOrgUnitId} END, UnitName={UnitName} WHERE Id=" + context.Request.Form[context.Request.Form["ids"] + "_OrganisationUnitStructure_Id"]);