Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi,
When I create node first time then if I published it then I want to set its property value.
If I publish next time then I don't want to set its property value.
Please share any idea or any reference.
Current Umbraco Version is : 6.2.4
Thanks.
Hi Sony
What kind of property value do you want to set and why? What is the scenario?
You should be able to use the ContentService API for achieving this though - https://our.umbraco.org/documentation/reference/management/services/contentservice
Just curious to figure out what and why to figure out whether it's necessary or not :)
Hope this helps.
/Jan
Thanks Jan for your reply.
I have solve it now myself.
below the code is working for me :
public class updatetext : ApplicationEventHandler { protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { ContentService.Published += ContentService_Publishing; }
void ContentService_Publishing(IPublishingStrategy sender, PublishEventArgs<Umbraco.Core.Models.IContent> e) { foreach (var content in e.PublishedEntities) { var test = content.GetValue<int>("test"); if (content.ContentType.Alias == "Product" && test == 0) { int count = 1; var contentService = ApplicationContext.Current.Services.ContentService; var student = contentService.GetById(content.Id); student.SetValue("test", count); student.SetValue("start", "first time published"); contentService.SaveAndPublishWithStatus(student); count++; BasePage.Current.ClientScript.RegisterClientScriptBlock(this.GetType(), "refresh301URLTracker", "$(window).load(function(){UmbClientMgr.contentFrame('editContent.aspx?id=" + content.Id + "');})", true); } } } }
Great! And very cool that you share your code so others can benefit from it or suggest improvements if they figure out something that can be done in a better way :)
Happy coding!
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
How to set Node's property value when node is first time published?
Hi,
When I create node first time then if I published it then I want to set its property value.
If I publish next time then I don't want to set its property value.
Please share any idea or any reference.
Current Umbraco Version is : 6.2.4
Thanks.
Hi Sony
What kind of property value do you want to set and why? What is the scenario?
You should be able to use the ContentService API for achieving this though - https://our.umbraco.org/documentation/reference/management/services/contentservice
Just curious to figure out what and why to figure out whether it's necessary or not :)
Hope this helps.
/Jan
Thanks Jan for your reply.
I have solve it now myself.
below the code is working for me :
public class updatetext : ApplicationEventHandler { protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { ContentService.Published += ContentService_Publishing; }
Hi Sony
Great! And very cool that you share your code so others can benefit from it or suggest improvements if they figure out something that can be done in a better way :)
Happy coding!
/Jan
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.