How to create a projection widget programmatically?

Topics: Administration, General, Writing modules
Feb 14, 2015 at 9:22 AM
Edited Feb 14, 2015 at 11:43 AM
Hi

I have created a query in my module with this code:
var myName = "something"
var theQuery = _contentManager.Create("Query");
 theQuery.As<TitlePart>().Title = myName + "Query";
var filterGroupRecord = new FilterGroupRecord();
var filterRecord = new FilterRecord()
{
    Category = "Content", Type = "ContentTypes", Description = myName , Position = 1, State = "<Form><Description>" + myName + "</Description>    <ContentTypes>" + myName + "</ContentTypes></Form>"
};
filterGroupRecord.Filters.Insert(0, filterRecord);
theQuery.As<QueryPart>().FilterGroups.Clear();
theQuery.As<QueryPart>().FilterGroups.Insert(0, filterGroupRecord);
And I know to create a projection widget I should use below code :
var theProjectionWidget = _contentManager.Create("ProjectionWidget");
theProjectionWidget .As<WidgetPart>().Title = myName + "ProjectionWidget";
theProjectionWidget .As<WidgetPart>().RenderTitle = false;
theProjectionWidget .As<WidgetPart>().Zone = "Content";
theProjectionWidget .As<WidgetPart>().Position = "1";
theProjectionWidget .As<WidgetPart>().LayerPart.Name = myName;
But I don't know how to assign the above query to this new projection widget.
How to assign query id to ProjectionPart.QueryLayoutRecordId???!!

I would appreciate any help.
Feb 14, 2015 at 11:43 AM
After some wrestling with code and debug I found solution for my question. Anybody with my problem can use this code:
theProjectionWidget.As<ProjectionPart>().Record.QueryPartRecord = new QueryPartRecord(){

            ContentItemRecord = theQuery.As<QueryPart>().ContentItem.Record,
            FilterGroups = theQuery.As<QueryPart>().FilterGroups,
            Id = theQuery.As<QueryPart>().Id,
            Layouts = theQuery.As<QueryPart>().Layouts,
            SortCriteria = theQuery.As<QueryPart>().SortCriteria

        };
Marked as answer by popcom on 2/14/2015 at 3:43 AM
Feb 15, 2015 at 4:03 PM
Good stuff. Thanks for this.
Feb 16, 2015 at 7:38 AM
trentnix wrote:
Good stuff. Thanks for this.
Here u r dude
Coordinator
Feb 17, 2015 at 4:49 AM
If you're going to cross-post, please provide links.
Feb 17, 2015 at 6:04 AM