Copied to clipboard

Flag this post as spam?

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


  • John C Scott 473 posts 1183 karma points
    Apr 25, 2022 @ 19:25
    John C Scott
    0

    Getting Form name by GUID from separate project

    A search provider using Azure Search is in a separate project from core & web v8.18 and in the same solution.

    Content is available through strongly typed models, however I am finding when I access the form picker I only have the GUID available and not the properties of the picked form.

    Can I pass the GUID to and get the basic form details? I need just the name of the form that is picked.

    There is no reference to the Umbraco.Forms namespace from my project if I try to add a using. Can this reference be added?

    The content to be indexed is received via a publishing event.

    All thoughts greatly valued. Thank you in advance :)

  • John C Scott 473 posts 1183 karma points
    Apr 26, 2022 @ 06:42
    John C Scott
    0

    I got some of the way there to an answer It made sense to me to extend the model so that the form name property is in the model. I found my way blindly to this and it still doesn't quite work right.

    public partial class FormBlock
        {
            public string FormName
            {
                get
                {
                    if (this.Form != null)
                    {
                        var fs = Umbraco.Web.Composing.Current.Factory.GetInstance<Umbraco.Forms.Core.Services.IFormService>();
                        var form = fs.Get(this.Form);
                        return form.Name;
                    }
                    else
                        return string.Empty;
                }
            }
        }
    

    it throws a SQL error and my guess is that what I am doing here is fundamentally wrong, not really sure if this is how I should create an instance of the service.

  • John C Scott 473 posts 1183 karma points
    Apr 26, 2022 @ 07:10
    John C Scott
    0

    I read this should be an injected dependency and not created like a v7 service. Does that mean it can't really be created as a part of the model?

  • John C Scott 473 posts 1183 karma points
    Apr 26, 2022 @ 11:17
    John C Scott
    0

    Yes - this was a truly terrible idea.

  • 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.

Please Sign in or register to post replies