Copied to clipboard

Flag this post as spam?

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


  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Jun 29, 2020 @ 17:07
    Ismail Mayat
    0

    Set tags not adding to cmsTags and cmsTagRelationShip tables

    Using v7.15.4 and using tags set as csv and in content pre save event I am doing:

    string tagPropertyAlias = Alert.GetModelPropertyType(x => x.ServiceNumber).PropertyTypeAlias;
    
            if(content.HasProperty(tagPropertyAlias))
            {
                //its stored as json array but cannot get it back as array so have to use string manipulation
                var serviceNumbers = content.GetValue<string>(tagPropertyAlias).Replace("[","").Replace("]","");
    
                if (!string.IsNullOrEmpty(serviceNumbers) && serviceNumbers.Contains(","))
                {
                    var badTags = serviceNumbers.Split(',');
                    List<string> goodTags = badTags.ToList();
    
                    //do we need to re add to tag manager??
                    content.SetTags(TagCacheStorageType.Csv,tagPropertyAlias,goodTags,true,"default");
                }
            }
    

    I am doing this because I want users to be able to paste csv list of values see where if you do this then you get funny results see https://our.umbraco.com/forum/using-umbraco-and-getting-started/102387-cut-and-paste-many-tags .

    So I have done it this way instead and it saves into content and it appears correctly in backoffice however the relation ships are not there, it seems as though set tags is not adding the relationships.

Please Sign in or register to post replies

Write your reply to:

Draft