private void LoadScriptForIndex()
        {
            if (IndexName == null)
            {
                return;
            }

            if (ScriptedIndexes.ContainsKey(indexName))
            {
                SelectedScript = ScriptedIndexes[indexName];
                return;
            }

            var id = ScriptedIndexResults.IdPrefix + indexName;

            ApplicationModel.DatabaseCommands.GetAsync(id)
            .ContinueOnSuccessInTheUIThread(doc =>
            {
                if (doc == null)
                {
                    ScriptedIndexes[indexName] = null;
                }
                else
                {
                    ScriptedIndexes[indexName] =
                        ApplicationModel.CreateSerializer()
                        .Deserialize <ScriptedIndexResults>(new RavenJTokenReader(doc.DataAsJson));
                }

                SelectedScript = ScriptedIndexes[indexName];
            });
        }