Take the 2-minute tour ×
Tridion Stack Exchange is a question and answer site for Tridion developers and administrators. It's 100% free, no registration required.

I am new to SDL Tridion developing GUI Extension. I have created config file. It is bringing text in context menu. But on click it is not hitting JavaScript from .js file.

following is my config code

<?xml version="1.0"?>
<Configuration xmlns="http://www.sdltridion.com/2009/GUI/Configuration/Merge" xmlns:cfg="http://www.sdltridion.com/2009/GUI/Configuration" xmlns:ext="http://www.sdltridion.com/2009/GUI/extensions" xmlns:cmenu="http://www.sdltridion.com/2009/GUI/extensions/ContextMenu">
  <resources cache="false">
    <cfg:filters/>
    <cfg:groups>
      <cfg:group name="Counter.Commands" merger="Tridion.Web.UI.Core.Configuration.Resources.CommandGroupProcessor" merge="always">
        <cfg:fileset>
          <cfg:file type="script">/Counter/Counter.js</cfg:file>
        </cfg:fileset>
        <cfg:dependencies>
         <cfg:dependency>Tridion.Web.UI.Editors.CME</cfg:dependency>
         <cfg:dependency>Tridion.Web.UI.Editors.CME.commands</cfg:dependency>
         <cfg:file type="reference">Counter.CommandSet</cfg:file>
        </cfg:dependencies>
      </cfg:group>
    </cfg:groups>
  </resources>
  <definitionfiles/>
  <extensions>
    <ext:editorextensions>
      <ext:editorextension target="CME">
        <ext:editurls />
        <ext:listdefinitions/>
        <ext:taskbars/>
        <ext:commands />
        <ext:commandextensions/>
        <ext:contextmenus>
          <ext:add>
            <ext:extension name="Counter" assignid="ext_Counter" insertbefore="cm_refresh">
              <ext:menudeclaration externaldefinition="">
                <cmenu:ContextMenuItem id="ext_Counter" name="Counter Count:" command="Counter"/>
              </ext:menudeclaration>
              <ext:dependencies>
                <cfg:dependency>Counter.Commands</cfg:dependency>
              </ext:dependencies>
              <ext:apply>
                <ext:view name="DashboardView"/>
              </ext:apply>
            </ext:extension>
          </ext:add>
        </ext:contextmenus>
        <ext:lists/>
        <ext:tabpages/>
        <ext:toolbars/>
        <ext:ribbontoolbars/>
      </ext:editorextension>
    </ext:editorextensions>
    <ext:dataextenders/>
  </extensions>
  <commands>
    <cfg:commandset id="Counter.CommandSet">
    <cfg:command name="Counter" implementation="Extensions.Counter"/>
    <cfg:dependencies>
    <cfg:dependency>Counter.Commands</cfg:dependency>
    </cfg:dependencies>
    </cfg:commandset>
  </commands>
  <contextmenus/>
  <localization/>
  <settings>
    <defaultpage>/Views/Default.aspx</defaultpage>
    <navigatorurl>/Views/Default.aspx</navigatorurl>
    <editurls/>
    <listdefinitions/>
    <itemicons/>
    <theme>
      <path/>
    </theme>
    <customconfiguration/>
  </settings>
</Configuration>

and my JavaScript code as follow:

Type.registerNamespace("Extensions");

Extensions.Counter = function Extensions$Counter() {
    Type.enableInterface(this, "Extensions.Counter");
    this.addInterface("Tridion.Cme.Command", ["Counter"]);
};

Extensions.Counter.prototype.isAvailable = function Counter$isAvailable(selection) {
    return true;
}

Extensions.Counter.prototype.isEnabled = function Counter$isEnabled(selection) {
    if (selection.getItems().length > 1)
        return false;
    else
        return true;
}

Extensions.Counter.prototype._execute = function Counter$_execute(selection) {
    selectedItem = selection.getItems()[0];
    prompt("Copy the Item ID using Ctrl/Cmd + C:", selection.getItems()[0]);
}

Thanks in advance.

i am getting error :Command 'Counter' is not registered on same question what it means

share|improve this question

2 Answers 2

up vote 12 down vote accepted

At quick glance, looks like you are adding the reference to your commandset from your resource group in the wrong place, you should add it like:

<cfg:fileset>
    <cfg:file type="script">/Counter/Counter.js</cfg:file>
    <cfg:file type="reference">Counter.CommandSet</cfg:file>
</cfg:fileset>

In your example you have it in the dependencies section, make sure to take it out of there.

Also make sure you are increasing the modification attribute in System.config after making your changes. If you are still seeing issues, try adding some logs (outside and inside your class) and checking the console window to see if they are getting hit (and to see if there are any errors anywhere) to see if there's an issue with your command or with the JavaScript not being included.

Hope that helps!

share|improve this answer

In your Js code try replacing your first five lines code with the below one :

Type.registerNamespace("Extensions");

Extensions.Counter = function Extensions.Counter() {

Type.enableInterface(this, "Extensions.Counter");
this.addInterface("Tridion.Cme.Command", ["Counter"]);
};

This may help.

share|improve this answer
1  
Hi SDLBeginner and thanks for sharing an answer! The above would actually cause a syntax error on the line Extensions.Counter = function Extensions.Counter() {. You can't have the "." within function names. –  Alex Klock Aug 18 at 13:13
    
Hi @AlexKlock .. but i used the same for one of the functionality extension long back. I am not sure weather this will throw any syntax error. Thank you for bringing this in my notice. –  SDLBeginner Aug 18 at 13:24
1  
Just to be clear SDLBeginner, you simply need to change the function name so that your second line of code becomes Extensions.Counter = function Extensions$Counter() {. It's only the name after the function keywords that can't contains dots, which is why they are often replaced with something like a $. –  Frank van Puffelen Aug 18 at 16:43
    
@FrankvanPuffelen i am getting Command "'Counter' is not registered" what it means –  Pankaj786 Aug 20 at 7:08

Your Answer

 
discard

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.