Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Updating a different page via CreateWritableClone

Vote:
 

When you call CreateWritableClone and get a PageData object you can modify then save it, what dictates what page this updates?

I have Page A and Page B.  I want to change Page B to be an exact clone of Page A.  I figured I could just call CreateWritableClone on Page A, then change some properties, and save it back, and it would save "into" Page B.

So, I called CreateWritableClone on Page A, then on the clode I changed the PageLink, ParentLink and PageGUID properties  to Page B's values and saved it.  I figured that with those properties changed, the clone would think it was from Page B and would update Page B.

Cannot insert duplicate key row in object 'dbo.tblPage' with unique index 'IDX_tblPage_PageGUID'.

So, it's trying to insert the clone as a new page, rather than updating Page B.

How do I get it to update Page B instead of inserting a new page?  In a larger sense, am I going about this the right way?  I need Page B to become an exactly copy of Page A -- is there some better method?

(For the record, I tried iterating the properties of Page A and calling SetValue on Page B, but found several problems, ranging from properties that couldn't be empty -- even though they were on Page A -- to CategoryList being read-only.)

#60325
Aug 03, 2012 18:33
Vote:
 

Deane, 

Would it be easier to just throw away Page B and re-create it using DataFactory.Instance.Copy(PageReference to PageA)?

 

or, I think the only way to safely update Page B would be to CreateWritableClone on Page B and set all the properties on the clone to that of Page A.

Enumerating over them should be straight forward. Then call DataFactory.Instance.Save(PageB) to commit the update.

#60328
Aug 06, 2012 9:56
Vote:
 

Neither solution will work.

To delete Page B would delete all of its children.  They would not come back on the copy.

Enumerating the properties sounds like it would work, but it's buggy.  You get several errors for properties that "can't be empty" (even though they are on Page A), and when you save, you always get "The CategoryList is read-only."  I worked through the bugs for a while, but it's just error after error, it seems.

#60345
Aug 06, 2012 14:45
Vote:
 

The empty errors are likely occuring as the "must contain value" logic has been applied after the origional pages have been created.

CategoryList Property types should be assignable, I have succsefully updated them before.

When enumerating the values, there are likely to be some system ones which shouldnt be changed - probably worth enumerating only the ones which can be changed in the editor ("Display in edit mode" checked).

 

 

#60351
Aug 06, 2012 16:24
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.