Dashboards & Visualizations

Get current app name with Javascript (Splunk.util.getCurrentApp() fails)

marco_sulla
Path Finder

Is there a way to get the current app name with Javascript?

I tried to use Splunk.util.getCurrentApp() from the console, but it fails. Reading the source code, it should return an attribute of the document body that does not exists. This happens also with the Search app. Furthermore, if I try to use it in my js code, JS gives me error because Splunk var is undefined.

Tags (2)
0 Karma
1 Solution

jeffland
SplunkTrust
SplunkTrust

Remember to require the right objects. If I'm not mistaken, it should be "splunkjs/mvc/utils" in the array and utils in the function, so a bit like this in your js:

require([
'splunkjs/mvc/simplexml/ready!',
"splunkjs/mvc/utils",
"jquery"
],
function(
    $,
    utils
    ) {
        var $ = require("jquery");
        ...

View solution in original post

jeffland
SplunkTrust
SplunkTrust

Remember to require the right objects. If I'm not mistaken, it should be "splunkjs/mvc/utils" in the array and utils in the function, so a bit like this in your js:

require([
'splunkjs/mvc/simplexml/ready!',
"splunkjs/mvc/utils",
"jquery"
],
function(
    $,
    utils
    ) {
        var $ = require("jquery");
        ...

rijutha
Explorer

Hi,

I am having a similar kind of issue with my lookup editor app customization. I have the following js code which gets the current app name using the Splunk Utils packages and I use the result to replace the hardcoded app name "luep" in the rest of the code. However in places where the path name with the app folder comes like in the require.config and define sections of the below code when I replace the app_name variable which contains the app name it doesn't replace as expected and gives an error saying undefined. Would you be able to help with this?

var app_name;

require(["splunkjs/mvc/utils"],
function (SplunkUtil)
{
app_name = SplunkUtil.getCurrentApp();

});
require.config({

paths:
{
datatables:"../app/"+app_name"/js/lib/DataTables/js/jquery.dataTables", //when replaced here it says undefined.
bootstrapDataTables:"../app/luep/js/lib/DataTables/js/dataTables.bootstrap",
text:"../app/luep/js/lib/text",
console:"../app/luep/js/lib/console"
},

shim:
 {
     bootstrapDataTables:
      {
          deps:
           ["datatables"]
      }
 }
});

define(["underscore","backbone","models/SplunkDBase","collections/SplunkDsBase","splunkjs/mvc","jquery","splunkjs/mvc/simplesplunkview","text!../app/luep/js/templates/LookupList.html",
"bootstrapDataTables","util/splunkd_utils","bootstrap.dropdown","css!../app/luep/css/LookupList.css","css!../app/luep/css/SplunkDataTables.css"],

    function(n,m,i,a,g,j,l,k,d,f)
    {
        var h=a.extend(
        {
            url:"apps/local?count=-1&search="+app_name,
            initialize:
            function()
            {
                a.prototype.initialize.apply(this,arguments)
            }
        });

        var o=a.extend(
        {
            url:"data/transforms/lookups?count=-1&search="+app_name,
            initialize:
            function()
            {
                a.prototype.initialize.apply(this,arguments)
            }
        });

        var b=a.extend(
        {
            url:"/servicesNS/"+Splunk.util.getConfigValue("USERNAME")+"/-/data/lookup-table-files?count=-1&search="+app_name,
            initialize:
            function()
            {
                a.prototype.initialize.apply(this,arguments)
            }
        });

        var c=a.extend(
        {
            url:"/servicesNS/nobody/-/storage/collections/config?count=-1&search="+app_name,
            initialize:function()
            {
                a.prototype.initialize.apply(this,arguments)
            }
        });
        var e=l.extend(
        {
            className:"LookupListView",
            defaults:
            {
                change_dropdown_titles:true
            },
            initialize:function()
            {
                this.options=n.extend({},this.defaults,this.options);
                this.change_dropdown_titles=this.options.change_dropdown_titles;
                this.filter_app=null;
                this.filter_type=null;
                this.filter_scope=null;
                this.filter_text=null;
                this.applied_filter=null;
                this.apps=null;
                this.data_table=null;
                this.retain_state=false;
                this.csv_lookups=new b();
                this.csv_lookups.on("reset",this.gotCSVLookups.bind(this),this);
                this.csv_lookups.fetch(
                {
                    success:function()
                    {
                        console.info("Successfully retrieved the CSV lookup files")
                    },
                    error:function()
                    {
                        console.error("Unable to fetch the CSV lookup files")
                    }
                });
                this.kv_lookups_supported=true;
                this.getKVLookups();
                this.apps=new h();
                this.apps.on("reset",this.gotApps.bind(this),this);
                this.apps.fetch(
                {
                    success:function()
                    {
                        console.info("Successfully retrieved the list of applications")
                    },
                    error:function()
                    {
                        console.error("Unable to fetch the apps")
                    }
                });
                this.lookup_transforms=new o();
                this.lookup_transforms.on("reset",this.gotLookupTransforms.bind(this),this);
                this.lookup_transforms.fetch(
                {
                    success:function()
                    {
                        console.info("Successfully retrieved the list of lookup transforms")
                    },
                    error:function()
                    {
                        console.error("Unable to fetch the lookup transforms")
                    }
                })
            },
            events:
            {
                "click .type-filter > .dropdown-menu > li > a":"onClickTypeFilter",
                "click .app-filter > .dropdown-menu > li > a":"onClickAppFilter",
                "click .scope-filter > .btn":"onClickScopeFilter",
                "change #free-text-filter":"applyFilter",
                "keyup #free-text-filter":"goFilter",
                "keypress #free-text-filter":"goFilter",
                "click .disable-kv-lookup":"openDisableKVLookupDialog",
                "click #disable-this-lookup":"disableLookup",
                "click .enable-kv-lookup":"enableLookup"
            },
            getKVLookups:function()
            {
                this.kv_lookups=new c();
                this.kv_lookups.on("reset",this.gotKVLookups.bind(this),this);
                this.kv_lookups.fetch(
                {
                    success:function()
                    {
                        console.info("Successfully retrieved the KV store lookup files")
                    },
                    error:function()
                    {
                        console.error("Unable to fetch the KV store lookup files")
                    },
                    complete:function(p,q)
                    {
                        if(p.status==404)
                        {
                            this.hideKVStoreOptions();
                            this.kv_lookups_supported=false
                        }
                    }
                    .bind(this)
                }
                )
            },
            hideKVStoreOptions:function()
            {
                j(".show-kv-supported-only",this.$el).hide();
                j(".show-kv-unsupported-only",this.$el).show()
            },
            setFilterText:function(r,q,p){if(typeof p==="undefined"){p="All"}if(this.change_dropdown_titles){if(p){j("."+r+" > .dropdown-toggle").html(q+": "+p+'<span class="caret"></span>')}else{j("."+r+" > .dropdown-toggle").html(q+'<span class="caret"></span>')}}},doFilter:function(t,s,r,q){if(typeof q=="undefined"){q=true}var p=r;if(r===null){p="All"}this.setFilterText(t,s,p);j("."+t+" > .dropdown-menu > li > a").each(function(){if(j(this).text()===p){j("i",this).removeClass("hide")}else{j("i",this).addClass("hide")}});if(q){this.applyFilter()}},onClickTypeFilter:function(q){var p=j(q.target).text();this.setTypeFilter(p)},setTypeFilter:function(p){if(p==="All"){this.filter_type=null}else{this.filter_type=p}this.doFilter("type-filter","Type",p)},onClickScopeFilter:function(q){var p=j(q.target).text();this.setScopeFilter(p)},setScopeFilter:function(p){var q="All";if(p==="All"||p===null){this.filter_scope=null}else{if(p.indexOf("Global")>=0){this.filter_scope="nobody";q="Global"}else{this.filter_scope=Splunk.util.getConfigValue("USERNAME");q="Mine"}}j(".scope-filter > .btn").each(function(){if(j(this).text()===q){j(this).addClass("active")}else{j(this).removeClass("active")}});this.applyFilter()},onClickAppFilter:function(q){var p=j(q.target).text();this.setAppFilter(p)},setAppFilter:function(p){if(p==="All"){this.filter_app=null}else{this.filter_app=p}this.doFilter("app-filter","App",p)},enableLookup:function(r){var s=j(r.target).data("name");var q=j(r.target).data("namespace");var p=j(r.target).data("owner");j.ajax({url:f.fullpath(["/servicesNS","nobody",q,"storage/collections/config",s,"enable"].join("/")),type:"POST",success:function(){console.info("KV store lookup enabled")}.bind(this),complete:function(t,u){if(t.status==403){console.info("Inadequate permissions to enable collection")}else{this.retain_state=true;this.getKVLookups()}}.bind(this),error:function(t,v,u){if(t.status!=403){console.info("KV store collection enablement failed")}}.bind(this)});return false},disableLookup:function(r){var s=j(r.target).data("name");var q=j(r.target).data("namespace");var p=j(r.target).data("owner");j.ajax({url:f.fullpath(["/servicesNS","nobody",q,"storage/collections/config",s,"disable"].join("/")),type:"POST",success:function(){console.info("KV store lookup disabled")}.bind(this),complete:function(t,u){if(t.status==403){console.info("Inadequate permissions to disable collection")}else{j("#disable-lookup-modal",this.$el).modal("hide");this.retain_state=true;this.getKVLookups()}}.bind(this),error:function(t,v,u){if(t.status!=403){console.info("KV store collection disablement failed")}}.bind(this)})},openDisableKVLookupDialog:function(r){var s=j(r.target).data("name");var q=j(r.target).data("namespace");var p=j(r.target).data("owner");j("#disable-this-lookup",this.$el).data("name",s);j("#disable-this-lookup",this.$el).data("namespace",q);j("#disable-this-lookup",this.$el).data("owner",p);j(".disable-lookup-name",this.$el).text(s);j(".disable-lookup-namespace",this.$el).text(q);j(".disable-lookup-owner",this.$el).text(p);j("#disable-lookup-modal",this.$el).modal();return false},goFilter:function(q){var p=q.keyCode||q.which;if(p==13){q.preventDefault()}this.applyFilter()},applyFilter:function(){var p=""+this.filter_type+":"+this.filter_app+":"+this.filter_scope+":"+j("#free-text-filter").val();if(p===this.applied_filter){return}this.applied_filter=p;if(this.filter_type!==null){this.data_table.columns(1).search("^"+this.filter_type+"$",true)}else{this.data_table.columns(1).search("")}if(this.filter_app!==null){this.data_table.columns(2).search("^"+this.filter_app+"$",true)}else{this.data_table.columns(2).search("")}if(this.filter_scope!==null){this.data_table.columns(3).search("^"+this.filter_scope+"$",true)}else{this.data_table.columns(3).search("")}this.filter_text=j("#free-text-filter").val();this.data_table.columns(0).search(j("#free-text-filter").val()).draw()},getAppDescriptionFromName:function(p){for(var q=0;q<this.apps.models.length;q++){if(this.apps.models[q].entry.attributes.name===p){return this.apps.models[q].entry.associated.content.attributes.label}}return p},gotCSVLookups:function(){this.renderLookupsList()},gotKVLookups:function(){this.renderLookupsList()},gotApps:function(){this.renderLookupsList()},gotLookupTransforms:function(){this.renderLookupsList()},endsWith:function(q,p){return q.indexOf(p,q.length-p.length)!==-1},isSupportedLookup:function(p){if(this.endsWith(p.name,".default")){return false}else{if(p.name===".DS_Store"){return false}else{return true}}},getLookupsCount:function(){var p=this.getLookupsJSON();if(p){return p.length}else{return 0}},getLookupsJSON:function(){var q=[];var p=null;var r=null;for(var s=0;s<this.csv_lookups.models.length;s++){if(this.csv_lookups.models[s].entry.acl.attributes.sharing==="global"||this.csv_lookups.models[s].entry.acl.attributes.sharing==="app"){r="nobody"}else{r=this.csv_lookups.models[s].entry.acl.attributes.owner}p={name:this.csv_lookups.models[s].entry.attributes.name,author:this.csv_lookups.models[s].entry.attributes.author,updated:this.csv_lookups.models[s].entry.attributes.updated,namespace:this.csv_lookups.models[s].entry.acl.attributes.app,owner:this.csv_lookups.models[s].entry.acl.attributes.owner,type:"csv",sharing:this.csv_lookups.models[s].entry.acl.attributes.sharing,endpoint_owner:r};if(!this.endsWith(this.csv_lookups.models[s].entry.attributes.name,".kmz")){q.push(p)}}for(var s=0;s<this.kv_lookups.models.length;s++){p={name:this.kv_lookups.models[s].entry.attributes.name,author:this.kv_lookups.models[s].entry.attributes.author,updated:this.kv_lookups.models[s].entry.attributes.updated,namespace:this.kv_lookups.models[s].entry.acl.attributes.app,owner:this.kv_lookups.models[s].entry.acl.attributes.owner,type:"kv",endpoint_owner:this.kv_lookups.models[s].entry.acl.attributes.owner,disabled:this.kv_lookups.models[s].entry.associated.content.attributes.disabled};q.push(p)}return q.filter(this.isSupportedLookup.bind(this))},getAppsJSON:function(t){if(typeof t==="undefined"){t=true}if(!this.apps){return[]}var s=[];var p=null;for(var r=0;r<this.apps.models.length;r++){p={name:this.apps.models[r].entry.attributes.name,label:this.apps.models[r].entry.associated.content.attributes.label};if(t){for(var q=0;q<this.csv_lookups.models.length;q++){if(this.csv_lookups.models[q].entry.acl.attributes.app===this.apps.models[r].entry.attributes.name){s.push(p);break}}for(var q=0;q<this.kv_lookups.models.length;q++){if(this.kv_lookups.models[q].entry.acl.attributes.app===this.apps.models[r].entry.attributes.name){s.push(p);break}}}else{s.push(p)}}var s=n.uniq(s,function(w,v,u){return w.name});return s},getLookupTransformsJSON:function(){if(!this.lookup_transforms){return[]}var p=[];for(var q=0;q<this.lookup_transforms.models.length;q++){if(this.lookup_transforms.models[q].entry.associated.content.attributes.type=="kvstore"){p.push({transform:this.lookup_transforms.models[q].entry.attributes.name,collection:this.lookup_transforms.models[q].entry.associated.content.attributes.collection})}else{if(this.lookup_transforms.models[q].entry.associated.content.attributes.type=="file"){p.push({transform:this.lookup_transforms.models[q].entry.attributes.name,filename:this.lookup_transforms.models[q].entry.associated.content.attributes.filename})}}}return p},getLookupTransform:function(q){var p=this.getLookupTransformsJSON();for(var r=0;r<p.length;r++){if(p[r].collection===q){return p[r].transform}if(p[r].filename===q){return p[r].transform}}},renderLookupsList:function(q){if(typeof q=="undefined"){q=this.retain_state}var p=j("#lookup-list-template",this.$el).text();j("#content",this.$el).html(n.template(p,{lookups:this.getLookupsJSON(),apps:this.getAppsJSON(),transforms:this.getLookupTransformsJSON(),kv_lookups_supported:this.kv_lookups_supported,getAppDescriptionFromName:this.getAppDescriptionFromName.bind(this),getLookupTransform:this.getLookupTransform.bind(this),filter_app:this.filter_app,filter_type:this.filter_type,filter_scope:this.filter_scope,filter_text:this.filter_text,lookups_count:this.getLookupsCount()}));this.data_table=j("#table",this.$el).DataTable({iDisplayLength:25,bLengthChange:false,searching:true,aLengthMenu:[[25,50,100,-1],[25,50,100,"All"]],bStateSave:true,fnStateLoadParams:function(r,s){return q},aaSorting:[[1,"asc"]],aoColumns:[null,null,null,null,{bSortable:false}]});this.setTypeFilter(this.filter_type);this.setAppFilter(this.filter_app);this.setScopeFilter(this.filter_scope)},render:function(){this.$el.html(k)}});return e});
0 Karma

rijutha
Explorer

var app_name;

require(["splunkjs/mvc/utils"],
function (SplunkUtil)
{
app_name = SplunkUtil.getCurrentApp();

});
require.config({

paths:
{
datatables:"../app/"+app_name+"/js/lib/DataTables/js/jquery.dataTables",
bootstrapDataTables:"../app/luep/js/lib/DataTables/js/dataTables.bootstrap",
text:"../app/luep/js/lib/text",
console:"../app/luep/js/lib/console"
},

shim:
 {
     bootstrapDataTables:
      {
          deps:
           ["datatables"]
      }
 }
});

define(["underscore","backbone","models/SplunkDBase","collections/SplunkDsBase","splunkjs/mvc","jquery","splunkjs/mvc/simplesplunkview","text!../app/luep/js/templates/LookupList.html",
"bootstrapDataTables","util/splunkd_utils","bootstrap.dropdown","css!../app/luep/css/LookupList.css","css!../app/luep/css/SplunkDataTables.css"],

    function(n,m,i,a,g,j,l,k,d,f)
    {
        var h=a.extend(
        {
            url:"apps/local?count=-1&search="+app_name,
            initialize:
            function()
            {
                a.prototype.initialize.apply(this,arguments)
            }
        });

        var o=a.extend(
        {
            url:"data/transforms/lookups?count=-1&search="+app_name,
            initialize:
            function()
            {
                a.prototype.initialize.apply(this,arguments)
            }
        });

        var b=a.extend(
        {
            url:"/servicesNS/"+Splunk.util.getConfigValue("USERNAME")+"/-/data/lookup-table-files?count=-1&search="+app_name,
            initialize:
            function()
            {
                a.prototype.initialize.apply(this,arguments)
            }
        });

        var c=a.extend(
        {
            url:"/servicesNS/nobody/-/storage/collections/config?count=-1&search="+app_name,
            initialize:function()
            {
                a.prototype.initialize.apply(this,arguments)
            }
        });
        var e=l.extend(
        {
            className:"LookupListView",
            defaults:
            {
                change_dropdown_titles:true
            },
            initialize:function()
            {
                this.options=n.extend({},this.defaults,this.options);
                this.change_dropdown_titles=this.options.change_dropdown_titles;
                this.filter_app=null;
                this.filter_type=null;
                this.filter_scope=null;
                this.filter_text=null;
                this.applied_filter=null;
                this.apps=null;
                this.data_table=null;
                this.retain_state=false;
                this.csv_lookups=new b();
                this.csv_lookups.on("reset",this.gotCSVLookups.bind(this),this);
                this.csv_lookups.fetch(
                {
                    success:function()
                    {
                        console.info("Successfully retrieved the CSV lookup files")
                    },
                    error:function()
                    {
                        console.error("Unable to fetch the CSV lookup files")
                    }
                });
                this.kv_lookups_supported=true;
                this.getKVLookups();
                this.apps=new h();
                this.apps.on("reset",this.gotApps.bind(this),this);
                this.apps.fetch(
                {
                    success:function()
                    {
                        console.info("Successfully retrieved the list of applications")
                    },
                    error:function()
                    {
                        console.error("Unable to fetch the apps")
                    }
                });
                this.lookup_transforms=new o();
                this.lookup_transforms.on("reset",this.gotLookupTransforms.bind(this),this);
                this.lookup_transforms.fetch(
                {
                    success:function()
                    {
                        console.info("Successfully retrieved the list of lookup transforms")
                    },
                    error:function()
                    {
                        console.error("Unable to fetch the lookup transforms")
                    }
                })
            },
            events:
            {
                "click .type-filter > .dropdown-menu > li > a":"onClickTypeFilter",
                "click .app-filter > .dropdown-menu > li > a":"onClickAppFilter",
                "click .scope-filter > .btn":"onClickScopeFilter",
                "change #free-text-filter":"applyFilter",
                "keyup #free-text-filter":"goFilter",
                "keypress #free-text-filter":"goFilter",
                "click .disable-kv-lookup":"openDisableKVLookupDialog",
                "click #disable-this-lookup":"disableLookup",
                "click .enable-kv-lookup":"enableLookup"
            },
            getKVLookups:function()
            {
                this.kv_lookups=new c();
                this.kv_lookups.on("reset",this.gotKVLookups.bind(this),this);
                this.kv_lookups.fetch(
                {
                    success:function()
                    {
                        console.info("Successfully retrieved the KV store lookup files")
                    },
                    error:function()
                    {
                        console.error("Unable to fetch the KV store lookup files")
                    },
                    complete:function(p,q)
                    {
                        if(p.status==404)
                        {
                            this.hideKVStoreOptions();
                            this.kv_lookups_supported=false
                        }
                    }
                    .bind(this)
                }
                )
            },
            hideKVStoreOptions:function()
            {
                j(".show-kv-supported-only",this.$el).hide();
                j(".show-kv-unsupported-only",this.$el).show()
            },
            setFilterText:function(r,q,p){if(typeof p==="undefined"){p="All"}if(this.change_dropdown_titles){if(p){j("."+r+" > .dropdown-toggle").html(q+": "+p+'<span class="caret"></span>')}else{j("."+r+" > .dropdown-toggle").html(q+'<span class="caret"></span>')}}},doFilter:function(t,s,r,q){if(typeof q=="undefined"){q=true}var p=r;if(r===null){p="All"}this.setFilterText(t,s,p);j("."+t+" > .dropdown-menu > li > a").each(function(){if(j(this).text()===p){j("i",this).removeClass("hide")}else{j("i",this).addClass("hide")}});if(q){this.applyFilter()}},onClickTypeFilter:function(q){var p=j(q.target).text();this.setTypeFilter(p)},setTypeFilter:function(p){if(p==="All"){this.filter_type=null}else{this.filter_type=p}this.doFilter("type-filter","Type",p)},onClickScopeFilter:function(q){var p=j(q.target).text();this.setScopeFilter(p)},setScopeFilter:function(p){var q="All";if(p==="All"||p===null){this.filter_scope=null}else{if(p.indexOf("Global")>=0){this.filter_scope="nobody";q="Global"}else{this.filter_scope=Splunk.util.getConfigValue("USERNAME");q="Mine"}}j(".scope-filter > .btn").each(function(){if(j(this).text()===q){j(this).addClass("active")}else{j(this).removeClass("active")}});this.applyFilter()},onClickAppFilter:function(q){var p=j(q.target).text();this.setAppFilter(p)},setAppFilter:function(p){if(p==="All"){this.filter_app=null}else{this.filter_app=p}this.doFilter("app-filter","App",p)},enableLookup:function(r){var s=j(r.target).data("name");var q=j(r.target).data("namespace");var p=j(r.target).data("owner");j.ajax({url:f.fullpath(["/servicesNS","nobody",q,"storage/collections/config",s,"enable"].join("/")),type:"POST",success:function(){console.info("KV store lookup enabled")}.bind(this),complete:function(t,u){if(t.status==403){console.info("Inadequate permissions to enable collection")}else{this.retain_state=true;this.getKVLookups()}}.bind(this),error:function(t,v,u){if(t.status!=403){console.info("KV store collection enablement failed")}}.bind(this)});return false},disableLookup:function(r){var s=j(r.target).data("name");var q=j(r.target).data("namespace");var p=j(r.target).data("owner");j.ajax({url:f.fullpath(["/servicesNS","nobody",q,"storage/collections/config",s,"disable"].join("/")),type:"POST",success:function(){console.info("KV store lookup disabled")}.bind(this),complete:function(t,u){if(t.status==403){console.info("Inadequate permissions to disable collection")}else{j("#disable-lookup-modal",this.$el).modal("hide");this.retain_state=true;this.getKVLookups()}}.bind(this),error:function(t,v,u){if(t.status!=403){console.info("KV store collection disablement failed")}}.bind(this)})},openDisableKVLookupDialog:function(r){var s=j(r.target).data("name");var q=j(r.target).data("namespace");var p=j(r.target).data("owner");j("#disable-this-lookup",this.$el).data("name",s);j("#disable-this-lookup",this.$el).data("namespace",q);j("#disable-this-lookup",this.$el).data("owner",p);j(".disable-lookup-name",this.$el).text(s);j(".disable-lookup-namespace",this.$el).text(q);j(".disable-lookup-owner",this.$el).text(p);j("#disable-lookup-modal",this.$el).modal();return false},goFilter:function(q){var p=q.keyCode||q.which;if(p==13){q.preventDefault()}this.applyFilter()},applyFilter:function(){var p=""+this.filter_type+":"+this.filter_app+":"+this.filter_scope+":"+j("#free-text-filter").val();if(p===this.applied_filter){return}this.applied_filter=p;if(this.filter_type!==null){this.data_table.columns(1).search("^"+this.filter_type+"$",true)}else{this.data_table.columns(1).search("")}if(this.filter_app!==null){this.data_table.columns(2).search("^"+this.filter_app+"$",true)}else{this.data_table.columns(2).search("")}if(this.filter_scope!==null){this.data_table.columns(3).search("^"+this.filter_scope+"$",true)}else{this.data_table.columns(3).search("")}this.filter_text=j("#free-text-filter").val();this.data_table.columns(0).search(j("#free-text-filter").val()).draw()},getAppDescriptionFromName:function(p){for(var q=0;q<this.apps.models.length;q++){if(this.apps.models[q].entry.attributes.name===p){return this.apps.models[q].entry.associated.content.attributes.label}}return p},gotCSVLookups:function(){this.renderLookupsList()},gotKVLookups:function(){this.renderLookupsList()},gotApps:function(){this.renderLookupsList()},gotLookupTransforms:function(){this.renderLookupsList()},endsWith:function(q,p){return q.indexOf(p,q.length-p.length)!==-1},isSupportedLookup:function(p){if(this.endsWith(p.name,".default")){return false}else{if(p.name===".DS_Store"){return false}else{return true}}},getLookupsCount:function(){var p=this.getLookupsJSON();if(p){return p.length}else{return 0}},getLookupsJSON:function(){var q=[];var p=null;var r=null;for(var s=0;s<this.csv_lookups.models.length;s++){if(this.csv_lookups.models[s].entry.acl.attributes.sharing==="global"||this.csv_lookups.models[s].entry.acl.attributes.sharing==="app"){r="nobody"}else{r=this.csv_lookups.models[s].entry.acl.attributes.owner}p={name:this.csv_lookups.models[s].entry.attributes.name,author:this.csv_lookups.models[s].entry.attributes.author,updated:this.csv_lookups.models[s].entry.attributes.updated,namespace:this.csv_lookups.models[s].entry.acl.attributes.app,owner:this.csv_lookups.models[s].entry.acl.attributes.owner,type:"csv",sharing:this.csv_lookups.models[s].entry.acl.attributes.sharing,endpoint_owner:r};if(!this.endsWith(this.csv_lookups.models[s].entry.attributes.name,".kmz")){q.push(p)}}for(var s=0;s<this.kv_lookups.models.length;s++){p={name:this.kv_lookups.models[s].entry.attributes.name,author:this.kv_lookups.models[s].entry.attributes.author,updated:this.kv_lookups.models[s].entry.attributes.updated,namespace:this.kv_lookups.models[s].entry.acl.attributes.app,owner:this.kv_lookups.models[s].entry.acl.attributes.owner,type:"kv",endpoint_owner:this.kv_lookups.models[s].entry.acl.attributes.owner,disabled:this.kv_lookups.models[s].entry.associated.content.attributes.disabled};q.push(p)}return q.filter(this.isSupportedLookup.bind(this))},getAppsJSON:function(t){if(typeof t==="undefined"){t=true}if(!this.apps){return[]}var s=[];var p=null;for(var r=0;r<this.apps.models.length;r++){p={name:this.apps.models[r].entry.attributes.name,label:this.apps.models[r].entry.associated.content.attributes.label};if(t){for(var q=0;q<this.csv_lookups.models.length;q++){if(this.csv_lookups.models[q].entry.acl.attributes.app===this.apps.models[r].entry.attributes.name){s.push(p);break}}for(var q=0;q<this.kv_lookups.models.length;q++){if(this.kv_lookups.models[q].entry.acl.attributes.app===this.apps.models[r].entry.attributes.name){s.push(p);break}}}else{s.push(p)}}var s=n.uniq(s,function(w,v,u){return w.name});return s},getLookupTransformsJSON:function(){if(!this.lookup_transforms){return[]}var p=[];for(var q=0;q<this.lookup_transforms.models.length;q++){if(this.lookup_transforms.models[q].entry.associated.content.attributes.type=="kvstore"){p.push({transform:this.lookup_transforms.models[q].entry.attributes.name,collection:this.lookup_transforms.models[q].entry.associated.content.attributes.collection})}else{if(this.lookup_transforms.models[q].entry.associated.content.attributes.type=="file"){p.push({transform:this.lookup_transforms.models[q].entry.attributes.name,filename:this.lookup_transforms.models[q].entry.associated.content.attributes.filename})}}}return p},getLookupTransform:function(q){var p=this.getLookupTransformsJSON();for(var r=0;r<p.length;r++){if(p[r].collection===q){return p[r].transform}if(p[r].filename===q){return p[r].transform}}},renderLookupsList:function(q){if(typeof q=="undefined"){q=this.retain_state}var p=j("#lookup-list-template",this.$el).text();j("#content",this.$el).html(n.template(p,{lookups:this.getLookupsJSON(),apps:this.getAppsJSON(),transforms:this.getLookupTransformsJSON(),kv_lookups_supported:this.kv_lookups_supported,getAppDescriptionFromName:this.getAppDescriptionFromName.bind(this),getLookupTransform:this.getLookupTransform.bind(this),filter_app:this.filter_app,filter_type:this.filter_type,filter_scope:this.filter_scope,filter_text:this.filter_text,lookups_count:this.getLookupsCount()}));this.data_table=j("#table",this.$el).DataTable({iDisplayLength:25,bLengthChange:false,searching:true,aLengthMenu:[[25,50,100,-1],[25,50,100,"All"]],bStateSave:true,fnStateLoadParams:function(r,s){return q},aaSorting:[[1,"asc"]],aoColumns:[null,null,null,null,{bSortable:false}]});this.setTypeFilter(this.filter_type);this.setAppFilter(this.filter_app);this.setScopeFilter(this.filter_scope)},render:function(){this.$el.html(k)}});return e});
0 Karma

jeffland
SplunkTrust
SplunkTrust

You should ask a new question about this, @rijutha

0 Karma

marco_sulla
Path Finder

Thank you, I used that to make the code independent from app name (if I want to create a production and a development app, or an xml and a django app):

var app_name;

require(["splunkjs/mvc/utils"], function (SplunkUtil) {
    "use strict";

    app_name = SplunkUtil.getCurrentApp();

    var libs = [
        "../app/" + app_name + "somelibrary", 
        // other dependences
    ];

    require(libs, function (SomeLibrary, /* other objects */) {
        // code block
    });
});
Get Updates on the Splunk Community!

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...

Combine Multiline Logs into a Single Event with SOCK: a Step-by-Step Guide for ...

Combine multiline logs into a single event with SOCK - a step-by-step guide for newbies Olga Malita The ...

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...