SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Best way to get from a custom action js command an webconfig appsetting key value, or another similar approach. ideas?


Reference a .js file on a custom action elements.xml

on my javascriptmethods.js file:

    function test(){
      alert('test message.');}

on my custom action elements.xml:

    ScriptSrc="/_layouts/.../javascriptmethods.js" Sequence="100">

   <CommandUIHandler Command="MyCommands.Alert"
   CommandAction="javascript:test();" />

what's missing?

share|improve this question
Everything appears to be right. I don't understand what's the problem and what's the need in the web.config? – Alex Boev Mar 5 '12 at 16:40
Alex, the example code is actually for the difficult of set a reference for a .js file on the custom action elements.xml. Probably is best to close this entry and make another question entry. – fallout Mar 6 '12 at 10:48
moved to,… – fallout Mar 6 '12 at 10:59
up vote 4 down vote accepted

For security reasons, you cannot access the web.config settings from javascript so the best approach would probably be to write a custom control / web part that can read the setting and then write it into the page into a script block.

share|improve this answer
thanks for the reply, any idea how I set an js in a CustomAction element? I follow some examples(…) but I never reach the methods on the .js file – fallout Mar 5 '12 at 15:15
Dave is absolutely right - you can render a variable in javascript via webpart or delegate control or something similar and then use it in custom action JS. What's the difficulty? What's the task? – Alex Boev Mar 5 '12 at 15:30

I wouldn't necessarilly rely on <appSettings> in SharePoint applications, mostly for things that are going to appear on the UI, or that should be easily configurable within the application.

Instead, would use some kind of Configuration Store approach, where you save the Key/Value setting in a List within SharePoint UI (such as SiteConfiguration).

Then, you can easily access the value using the javascript client object model.

Example config store:

share|improve this answer
Something within SharePoint is also easier to manage, especially on large farms as it only has to be changed in one place. It can also optionally be managed by end users, allowing them more control (if needed) – Dave Wise Mar 5 '12 at 23:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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