Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mathias Hove 3 posts 23 karma points
    May 03, 2016 @ 17:52
    Mathias Hove
    0

    Create extra textstring in repeatable texstring programmatically

    Hi there.

    I am trying to create an extra texstring in the new datatype repeatable texstring. Is that at all possible??

    I have a property with the alias "test", wich a repeatable textstring. In this example i want to save emails programmatically to the array of textstrings.

    I am going for 1 textstring per email. So that you can access the emails from umbraco admin.

    I have the following code at the moment

    var contentService = ApplicationContext.Services.ContentService;
    
                IPublishedContent root = Umbraco.TypedContentAtRoot().First();
    
                var newsletter = root.Descendant("boletinInformativo");
    
                //Test is the alias for repeatable textstring
                var mailsInNewsletter = newsletter.GetPropertyValue<string[]>("test");
                var getNewsletter = contentService.GetById(newsletter.Id);
    
                // This is where i am quite lost i have email as a parameter in the actionresult that i want to assign
                getNewsletter.SetValue("test", mailsInNewsletter + ??? );
    
                contentService.SaveAndPublishWithStatus(getNewsletter);
    
                return Json("yes", JsonRequestBehavior.AllowGet);
    

    I hope you have an idea of what i am trying to achieve.

    Thank you!

  • Ben Gdovicak 5 posts 34 karma points
    Jan 10, 2017 @ 15:56
    Ben Gdovicak
    0

    Mathias, were you ever able to solve this issue? We are running into the exact same issues and cannot find a solution either.

  • Christopher Crawford 5 posts 109 karma points
    Jan 10, 2017 @ 17:16
    Christopher Crawford
    3

    Found the solution -- for repeatable strings (and I would imagine any type of list), you need to segment the different line items by (ironically enough) a new line. Code is as follows:

    if (content.HasProperty(propertyName))
        content.SetValue(propertyName, "item1" + Environment.NewLine + "item2");
    
Please Sign in or register to post replies

Write your reply to:

Draft