6

I have been working on a problem for a bit now, and coming back to it again. I have most of it taken care of, thanks to previously posted questions Sitecore 7.2 parsing a droplink field in viewmodel, but I am still having an issue getting the needed value out of the droplink field.

I have a field template, called EventInfo, which has two properties, EventName and EventGuidNumber. Both are single-line text field types.

Pic 1

EventName has the acronym we use for the event, EventGuidNumber has the GUID our association management DB has for the event. I am trying to use the EventGuidNumber in our custom event code, to dynamically pull schedules, speakers, attendees, etc.

The EventInfo field template is used in the droplink field called NetForumID.

Pic 2

The NetForumID droplink uses the list of eventinfo items as the data source.

Pic 3

The NetForumID droplink is part of the overall Event template.

Pic 4

Here is a section of code from the model:

[SitecoreType(TemplateId = "{C65FF46A-5E22-48E1-BB73-D0B2A82AD691}", AutoMap = true)] /*Event ID template*/
public class EventIdDropdown
{
    [SitecoreField("NetForumId")]
    public virtual Guid Id { get; set; }

    public virtual NetForumEvent NetForumId { get; set; }
}

[SitecoreType(TemplateId = "{36371859-7FF2-47D0-86F1-1579416AA584}", AutoMap = true)]
public class Event
{
    public virtual EventIdDropdown EventGuidNumber { get; set; }
}

When I test it, the correct property GUID shows up in EventIdDropdown Id, but NetForumId remains null. I have tried using various permutations of code, including changing NetforumId to EventGuidNumber, and changing the template from the existing GUID (which points to the template EventInfo) to the GUID for the overall Event template. In each case, the result is the same - EventIdDropdown.Id has a GUID value, EventIdDropdown.NetForumId remains null.

We are on Sitecore7.2 and using GlassMapper 3.

What am I missing? To me, the issue appears to be that I am not hooking into the actual value of the droplink, EventGuidNumber, correctly, but I am stumped on what else to try.

Thanks in advance!

  • Can you cleanly explain your template and field structure, either using tables or screenshots, because what you are saying and what you are doing in code seems to be completely different things to me, but maybe I have misunderstood everything. – jammykam Aug 16 '18 at 3:37
  • @jammykam - screenshots and explanations added to the post. Thanks for reviewing! – chipsterva69 Aug 16 '18 at 11:46
3

Your model definitions look to be incorrect. You need 2 separate model definitions, one for each template type. To map the NetForumId field from the Event template you need to set the property to the correct model type you want returned, i.e. EventInfo, and GlassMapper will take care of getting the linked item and mapping it.

[SitecoreType(TemplateId = "{eventinfo-template-guid}", AutoMap = true)]
public class EventInfo 
{
    [SitecoreId]
    public virtual Guid Id { get; set;} //Sitecore Item Id

    public virtual string EventName { get; set; }

    public virtual string EventGuidNumber { get; set; }
}

[SitecoreType(TemplateId = "{event-template-guid}", AutoMap = true)]
public class Event
{
    [SitecoreId]
    public virtual Guid Id { get; set;}

    [SitecoreField("Event Abstract")]       
    public virtual string EventAbstract { get; set; }

    public virtual EventInfo NetForumId { get; set; }

    [SitecoreField("Event Description")]
    public virtual string EventDescription { get; set; }

    // any other mappings...
}

Notice that the NetForumId property returns EventInfo type. This should map the guid-type field in Sitecore to the strongly typed model for the value the user has selected. You can then render or access the values:

@model MyProject.Models.Event

<div>
    @Model.EventAbstract 
    @Model.NetForumId.Id
    @Model.NetForumId.EventName 
    @Model.NetForumId.EventGuidNumber 
</div>
| improve this answer | |
  • That did the trick. You are the bomb, sir. Thank you very much!! – chipsterva69 Aug 17 '18 at 19:50
0

You can use similar below:

    [SitecoreType(TemplateId = "{xxxxxx-xxxx-xxxx-xxxx-xxxxxx}", AutoMap = true)]
public interface IMenuItem
{
    string Title { get; set; }
    [SitecoreQuery("./*[@@templateid='{xxxxxx-xxxx-xxxx-xxxx-xxxxxx}']", IsRelative= true)]
    IEnumerable<ISubMenuItem> SubMenuItems { get; set; }
}
    [SitecoreType(TemplateId = "{xxxxxx-xxxx-xxxx-xxxx-xxxxxx}", AutoMap = true)]
public interface ISubMenuItem
{
    string Title { get; set; }
}

Here submenuitem are droplink type, we map that as IEnum.

| improve this answer | |
  • thanks for the code, but I am still not getting anything out of the EventGuidNumber field. When I update my code as you have here and debug it, IEnumerable<NetForumEvent> netforumEvents remains null. – chipsterva69 Aug 17 '18 at 14:41
  • I just update the code, Please look into this IEnum null because glass mapper can't identify children, need to use sitecore query. Please have a look. – Arun Sharma Aug 18 '18 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.