November Happy Hour will be moved to Thursday December 5th.

Working with projects programmatically.

Vote:
 

Hi All.

Creating a scheduled job which is supposed to migrate some data from one property to another (for two content types) in a controlled manner. 
For this I would like to create a project so its easier for the editor to see what has changed and can publish one item at the time, or everything if editor is happy with the changes.

The job is supposed to be a one time job, not to be run several times.

The job creates does the following:

  1. Create a new project
  2. Iterate through all active language branches
  3. Go through every instance of BlockTypeX; make changes (e g migrate data from Property1 to Property2)
  4. Add instance of BlockTypeX instance to project.
  5. Save BlockTypeX instance with SaveAction
  6. Go through every instance of PageTypeY; make changes (e g migrate data from Property1 to Property2)
  7. Add instance of PageTypeY instance to project.
  8. Save PageTypeY instance with SaveAction

We however get an error when adding instance to project when an instance of BlockTypeX instance is added to project when another language branch already has been added: "An item with same key has already been added."  So i guess language branch has to be referenced to the project item?!

The documentation is not helpful :D Seems its missing a lot regarding the programmic workflow  ;)

#330562
Sep 26, 2024 13:19
Vote:
 

Hi Jonas

If you look at the SDK documentation for the project item you will see that it takes a Language property 

However I assume your already setting this property and the issue you have is that the content link is not unique per language branch and therefore when you try and save the project item it is telling you it already exists in the project.

I would check you logic to ensure that when you get the content and modify that the content is per language to ensure you get a unique content reference / link per language branch.

Thanks

Paul

#330563
Sep 26, 2024 14:07
Jonas Boman - Sep 26, 2024 15:03
Thanks, I will investigate and get back to you. :)
Vote:
 

Would you mind posting some of your code?

Also, for this one time jobs I'd recommend you to use a terminal app instead of scheduled jobs. I wrote a blog post on how to get started https://www.herlitz.io/2024/02/22/optimizely-cms-in-a-terminal-console-app/

Sample source https://github.com/EricHerlitz/optimizely-cms-terminal

#330725
Edited, Sep 30, 2024 7:28
Vote:
 

Here's a blog post that's (I think) doing something similar: https://www.cdisol.blog/2021/04/30/handle-episerver-projects-programmatically/

#330778
Oct 01, 2024 22:12
* 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.