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?

  • 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, 2012 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, 2012 at 10:48
  • moved to, sharepoint.stackexchange.com/questions/30914/…
    – fallout
    Mar 6, 2012 at 10:59

2 Answers 2


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.

  • thanks for the reply, any idea how I set an js in a CustomAction element? I follow some examples(blog.voyta.net/2010/09/12/…) but I never reach the methods on the .js file
    – fallout
    Mar 5, 2012 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, 2012 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: http://spconfigstore.codeplex.com/

  • 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, 2012 at 23:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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