Surendra Sharma

Surendra Sharma

Search This Blog

Friday, November 15, 2019

How to get Sitecore multilist items details in GraphQL

I have graphQL query for my JSS app as

{
  search(fieldsEqual: [{name: "_fullpath", value: "/sitecore/content/abc"}]
  , keyword: "") {
    results {
      items {
        item {
          ... on Brand {
            heading {
              value
            }
            questionList {
              value
            }
          }
        }
      }
    }
  }
}

Here "QuestionList" is a list field for which I am getting output with Item ids separated by pipe "|" as

"questionList": {
  "value": "{79BADBCE-3824-4664-B74C-D5D931154E86}|{2D0FCE78-8377-4A1E-B47B-A3BDBB6D8D62}"
}

But instead of this items ids, how to get multilist items details?

For this we must use "targetItems" cluase as

{
  search(fieldsEqual: [{name: "_fullpath", value: "/sitecore/content/abc"}
   ], keyword: "") {
    results {
      items {
        item {
          ... on Brand {
            heading {
              value
            }
            questionList {
              value
              name
              targetItems {
                id
                name
                ... on Question
                {
                  questionstatement {value}
                }
              }
            }
          }
        }
      }
    }
  }
}

As you can observe here we can use strongly type items "Question" inside of "targetItems". Its output is

{
  "data": {
    "search": {
      "results": {
        "items": [
          {
            "item": {
              "heading": {
                "value": "This is Heading"
              },
              "questionList": {
                "value": "{79BADBCE-3824-4664-B74C-D5D931154E86}|{2D0FCE78-8377-4A1E-B47B-A3BDBB6D8D62}",
                "name": "questionList",
                "targetItems": [
                  {
                    "id": "79BADBCE38244664B74CD5D931154E86",
                    "name": "Question 1",
                    "questionstatement": {
                      "value": "Question 1"
                    }
                  },
                  {
                    "id": "2D0FCE7883774A1EB47BA3BDBB6D8D62",
                    "name": "Question 2",
                    "questionstatement": {
                      "value": "Question 2"
                    }
                  }
                ]
              }
            }
          }
        ]
      }
    }
  }
}

I hope this trick helps you to write GraphQL queries in better way for Sitecore JSS app.

Tuesday, October 29, 2019

Multilist in Sitecore JSS App

For the list data, Sitecore JSS offering "ContentList" as a field datatype. When you deploy it in Sitecore, it converts into "Treelist".

But what to do if you need "Multilist" instead of Treelist at Sitecore side?

Solution:
 

You have to specify "MultiList" as a string type when you define the Sitecore field definition for the component as

name: 'content'type: CommonFieldTypes.RichText },
name: 'articleList'type: 'MultiList'},

As you can notice here I defined "ArticleList" field as a "MultiList" datatype.

You can also set the datasource or query with this Multilist field definition as


name: 'articleList'type: 'MultiList'source: `query:./Articles/*`, },

Here I have set the datasource as a child folder "articles" of current Sitecore context item.

I hope this quick tip help you in Sitecore JSS App development.

Wednesday, October 23, 2019

Problem with Sitecore GraphQL on Azure

We have deployed JSS App on Sitecore instance running on Azure.

For one of the component we are using GraphQL which is perfectly working on local machine.


But when we deploy it on Azure our GraphQL query was not returning anything.

Our query was


var query = `{
search(fieldsEqual: [{name: "_fullpath",
value: "/sitecore/content/myjssproj/Content/BlogsCollection/ContentListField/*"}
])

As you can note, we have used "fieldsEqual" parameter and pass the name and value. You will get this query result on your local machine but this is not going to work on Azure.

I think this is because we are using "Azure Search" and Azure have limitation of 1000 fields index. It may be possible that Azure search not indexed system fields.

So if you want to use Azure Search with GraphQL you should rewrite your query with "rootItem" parameter as


var query = `{
search(rootItem: "/sitecore/content/myjssproj/Content/BlogsCollection/ContentListField/*"
)

Other alternative is to use SOLR as a search on Azure. I find this link is very simple and handy to install SOLR on azure.

Fix : Sitecore error - The type initializer for 'System.Drawing.ToolboxBitmapAttribute' threw an exception.

Our Sitecore website was running fine on Azure. But one day when we tried to open Content Editor, we started to receive error "The type initializer for 'System.Drawing.ToolboxBitmapAttribute' threw an exception."

As we have to update the content urgently and our Content editor was unable to update any content, so for the time being we updated those content from "DB browser" screen by accessing https://mysc.azurewebsites.net/sitecore/admin/dbbrowser.aspx.

However this was temporary solution, we have to resolve this issue anyway.


Solution:- 

Somewhere on web I read that the cause of this type of error is temp files on server.

As our instance was running on Azure, so we updated web.config file by editing some comment in the hope that it will recycle the app pool but this trick did not worked.


Next thing we tried to "Restart" the web app and once app was up, our content editor able to access content editor and updated content successfully.


I think App service restart operation removed those temp files and fixed the issue.

Sunday, October 13, 2019

eBook : Sitecore xDB to xConnect

Sharing my new eBook with Sitecore community - "Sitecore xDB to xConnect".

You can read and download this ebook from here:



I hope you like this eBook.

Please leave your comments or share this eBook if it’s useful for you.
 

Wednesday, September 18, 2019

Enable Unicorn for Sitecore websites


Below files are required in order to enable Unicorn on any Sitecore website i.e. if you want to access http://<sitecorewebiste>/Unicorn.aspx, put below files in bin folder
  • Configy.dll
  • Kamsar.WebConsole.dll
  • MicroCHAP.dll
  • Rainbow.dll
  • Rainbow.Storage.Sc.dll
  • Rainbow.Storage.Yaml.dll
  • Unicorn.dll

Config files

  • All config files under "App_Config\Include\Unicorn" folder
  • Rainbow.config

You should make your own project sepcific config file to serialize Sitecore items using Unicorn.

For JSS App, you can create unicorn file "Include\zzz\JSS.Serialization.config" something like 

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">

  <sitecore>
    <unicorn>
      <configurations>
        <configuration name="SitecoreJSSUnicorn" description="Sitecore JSS Serilization using Unicorn">
          <targetDataStore physicalRootPath="D:\Projects\MyJSSProject\Sitecore\Serialization\JSS Site Items" useDataCache="false" type="Rainbow.Storage.SerializationFileSystemDataStore, Rainbow" singleInstance="true"/>
          <predicate type="Unicorn.Predicates.SerializationPresetPredicate, Unicorn" singleInstance="true" >
            <!--Media-->
            <include name="SitecoreUnicorn.MediaOuter.JSS" database="master" path="/sitecore/media library/products-myjssproject">
              <!-- <exclude children="true"/> -->
            </include>
            <!--Media-->
            <include name="SitecoreUnicorn.MediaInside.JSS" database="master" path="/sitecore/media library/Project/JSSTenant/products-myjssproject">
              <!-- <exclude children="true"/> -->
            </include>           
            <!--Tempaltes-->
            <include name="SitecoreUnicorn.Template.JSS" database="master" path="/sitecore/templates/Project/products-myjssproject">
              <!-- <exclude children="true"/> -->
            </include>
            <include name="SitecoreUnicorn.Placeholders.JSS" database="master" path="/sitecore/layout/Placeholder Settings/Project/products-myjssproject">
              <!-- <exclude children="true"/> -->
            </include>
            <include name="SitecoreUnicorn.Layout.JSS" database="master" path="/sitecore/layout/Layouts/Project/products-myjssproject">
              <!-- <exclude children="true"/> -->
            </include>
            <include name="SitecoreUnicorn.Renderings.JSS" database="master" path="/sitecore/layout/Renderings/Project/products-myjssproject">
              <!-- <exclude children="true"/> -->
            </include>
            <include name="SitecoreUnicorn.Content.JSS" database="master" path="/sitecore/content/MyJSSTenant/products-myjssproject">
              <!-- <exclude children="true"/> -->
            </include>                  
          </predicate>
        </configuration>
      </configurations>
    </unicorn>
  </sitecore>
</configuration>