locked
Custom Action Query String Based on Column RRS feed

  • Question

  • Hi,

    I am new to Sharepoint and trying to become familiar with Sharepoint 2010 and Sharepoint Designer. I am working with a custom action, I want this action to redirect to a new URL (which is actually the URL of a list) I want to be able to add to the end of the url a Query String which has the value of a column. I am able to do this with {ItemId} but when I try it with another field it doesn’t work and {ItemId} really doesn't help me here. Here is an example of what I am trying: domain/list/view.aspx?querystring={colname}

    I am not sure if maybe I am just not using the right syntax because the “{colname}” is always evaluated as a literal, except for when I use {ItemId}. So am I making a mistake somewhere, or is something like this not possible through SPD? I don’t have access to Microsoft Visual Studio, nor would I really understand any of the code at this point.

    Thanks in advance for your help!!

    Tuesday, July 24, 2012 4:46 PM

Answers

  • Hi,

    I dont think you would be able to do that with SPD. You need to write a custom action code with some javascript to get the column name value and pass it as querystring. If you are worried abt access into the sharepoint server, You can even have a sandboxed solution to deploy this custom action. All you need is  a site collection admin permission to deploy the WSP in your site.

    The code for the custom action is as follows,Elements.xml file

    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <CustomAction
      Description="MySearch"
      Title="MySearch!"
      Id="{E538E8C7-65DA-454E-AD87-4A603B6CC569}"
      Location="CommandUI.Ribbon"
      RegistrationId="100"
      RegistrationType="List"
      Sequence="0"   
      Rights="ViewListItems"
      xmlns="http://schemas.microsoft.com/sharepoint/">
        <CommandUIExtension xmlns="http://schemas.microsoft.com/sharepoint/">
          <!-- Define the (UI) button to be used for this custom action -->
          <CommandUIDefinitions>
            <CommandUIDefinition Location="Ribbon.ListItem.Actions.Controls._children">
              <Button Id="{B511A716-54FF-4EAE-9CBE-EA02B51B626E}"
              Command="{4E2F5DC0-FE2C-4466-BB2D-3ED0D1917763}"         
              Sequence="0"
              LabelText="MySearch"
              Description="MySearch"
              TemplateAlias="o1"
    />
            </CommandUIDefinition>
          </CommandUIDefinitions>
          <CommandUIHandlers>
            <!-- Define the action expected on the button click -->
            <CommandUIHandler Command="{4E2F5DC0-FE2C-4466-BB2D-3ED0D1917763}" CommandAction="javascript:
                var ctx = new SP.ClientContext.get_current();
                var currentListGuid = SP.ListOperation.Selection.getSelectedList();
                var currentWeb = ctx.get_web();
                ctx.load(currentWeb);
                
                var currentList = currentWeb.get_lists().getById(currentListGuid);
                ctx.load(currentList);
                
                var items = SP.ListOperation.Selection.getSelectedItems();
                
                var listitem;
                for (k in items) {
                    listitem = currentList.getItemById(items[k].id);
                    break;
                }
                  
                ctx.load(listitem);
                ctx.executeQueryAsync(Function.createDelegate(listitem, function () {
                                                                                        window.open('http://www.bing.com/search?q='.concat(escape(listitem.get_item(COLUMNNAME))));
                                                                                    }
                  
                                                                ),null);
                " />
                 
          </CommandUIHandlers>
        </CommandUIExtension>
      </CustomAction>
    </Elements>


    Sathish

    • Marked as answer by Pengyu Zhao Friday, August 3, 2012 9:14 AM
    Monday, July 30, 2012 9:36 AM

All replies

  • Hi,

    You can refer to this article to see if it could help.

    Connect a Query String (URL) Filter Web Part to another Web Part:

    http://office.microsoft.com/en-us/sharepoint-server-help/connect-a-query-string-url-filter-web-part-to-another-web-part-HA010250999.aspx

    Thanks


    Pengyu Zhao

    TechNet Community Support

    Monday, July 30, 2012 6:26 AM
  • Hi,

    I dont think you would be able to do that with SPD. You need to write a custom action code with some javascript to get the column name value and pass it as querystring. If you are worried abt access into the sharepoint server, You can even have a sandboxed solution to deploy this custom action. All you need is  a site collection admin permission to deploy the WSP in your site.

    The code for the custom action is as follows,Elements.xml file

    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <CustomAction
      Description="MySearch"
      Title="MySearch!"
      Id="{E538E8C7-65DA-454E-AD87-4A603B6CC569}"
      Location="CommandUI.Ribbon"
      RegistrationId="100"
      RegistrationType="List"
      Sequence="0"   
      Rights="ViewListItems"
      xmlns="http://schemas.microsoft.com/sharepoint/">
        <CommandUIExtension xmlns="http://schemas.microsoft.com/sharepoint/">
          <!-- Define the (UI) button to be used for this custom action -->
          <CommandUIDefinitions>
            <CommandUIDefinition Location="Ribbon.ListItem.Actions.Controls._children">
              <Button Id="{B511A716-54FF-4EAE-9CBE-EA02B51B626E}"
              Command="{4E2F5DC0-FE2C-4466-BB2D-3ED0D1917763}"         
              Sequence="0"
              LabelText="MySearch"
              Description="MySearch"
              TemplateAlias="o1"
    />
            </CommandUIDefinition>
          </CommandUIDefinitions>
          <CommandUIHandlers>
            <!-- Define the action expected on the button click -->
            <CommandUIHandler Command="{4E2F5DC0-FE2C-4466-BB2D-3ED0D1917763}" CommandAction="javascript:
                var ctx = new SP.ClientContext.get_current();
                var currentListGuid = SP.ListOperation.Selection.getSelectedList();
                var currentWeb = ctx.get_web();
                ctx.load(currentWeb);
                
                var currentList = currentWeb.get_lists().getById(currentListGuid);
                ctx.load(currentList);
                
                var items = SP.ListOperation.Selection.getSelectedItems();
                
                var listitem;
                for (k in items) {
                    listitem = currentList.getItemById(items[k].id);
                    break;
                }
                  
                ctx.load(listitem);
                ctx.executeQueryAsync(Function.createDelegate(listitem, function () {
                                                                                        window.open('http://www.bing.com/search?q='.concat(escape(listitem.get_item(COLUMNNAME))));
                                                                                    }
                  
                                                                ),null);
                " />
                 
          </CommandUIHandlers>
        </CommandUIExtension>
      </CustomAction>
    </Elements>


    Sathish

    • Marked as answer by Pengyu Zhao Friday, August 3, 2012 9:14 AM
    Monday, July 30, 2012 9:36 AM