Using SPAutocomplete with a DataSource in Another Site Collection

Coordinator
Feb 11, 2011 at 2:58 PM
Originally posted by rajdeep1510 Today at 1:08 AM on the SPAutocomplete documentation page.

This one is just excellent. I am using it successfully. But does it work in cross site ? I want to use this from a site collection and want to access the list present in another site collection. some thing like this :

$().SPServices.SPAutocomplete({
WebURL: "/sites/AnotherSiteCollection",
sourceList: "Test",

sourceColumn: "ID",
columnName: "Enter the No",
numChars: 1,
ignoreCase: true,
slideDownSpeed: 100,
debug: true
});

//This webUrl is of AnotherSiteCollection and the code is in ASiteCollection. Presently its not populating the records. Am I missing something ?

Coordinator
Feb 11, 2011 at 3:24 PM

This ought to work, however, there are reasons why it wouldn't. They generally boils down to authentication issues. As long as your user has access to the other Site Collection without any additional login, you should be OK. Windows Auth is always cleanest, of course.

M.

Feb 24, 2011 at 7:13 AM
Edited Feb 24, 2011 at 7:14 AM

Hi,

Sorry to say but it is not working from another site collection :( Same code is working when the list is present in the same site collection but if the list is in different site collection there is no error but its not able to pull the records. I have full rights to both the site collections.

Anyone tried so far this kind of scenario ? Please let me know

Thanks

Rajdeep

Feb 24, 2011 at 3:33 PM

Hi,

To test your scenario I created a site collection at the root of a web application and a sub site collection:
sitecoll1: http://sitecoll1
sitecoll2: http://sitecoll1/sites/sitecoll2

On a page at sitecoll1 I put a CEWP with the following code:

        $().SPServices.SPAutocomplete({
            WebURL: "/sites/SiteColl2",
            sourceList: "Customers",
            sourceColumn: "Title",
            columnName: "magic2",
            numChars: 2,
            ignoreCase: true,
            slideDownSpeed: "fast",
            processingIndicator: "<img src='_layouts/images/REFRESH.GIF'/>",
            debug: true
        });

and I create a div:
 <input id="autocompletebox" Title="magic2"/>

At SiteColl2 I created a custom list Customers.
As soon as I type something in the textbox I get results from the list on the other site collection.

Represents this your scenario?

Regards, Anita

Jun 14, 2011 at 10:33 AM

Sorry for my delayed response. Yes Anita it did work.  had some cross site authentication issue.

Thanks for your reply. But exploring more onto this I am trying to use CAMLQuery option, so that I can filter more from the result set. Now in my column I have Active, Prioritized and High status. I have written the below query fragment to add with the existing CAML. But it doesn't seem to work. It is returning all the records.

var caml = "<Or><Or><Eq><FieldRef Name='Status' /><Value Type='Choice'>Prioritized</Value></Eq><Eq><FieldRef Name='Status'/><Value Type='Choice'>Active</Value></Eq></Or><Eq><FieldRef Name='Status' /><Value Type='Choice'>High</Value></Eq><Or>";

     $().SPServices.SPAutocomplete({
            WebURL: "/sites/SiteColl2",
            sourceList: "Customers",
            sourceColumn: "Title",
            columnName: "magic2",

            CAMLQuery: caml,

            numChars: 2,
            ignoreCase: true,
            slideDownSpeed: "fast",
            processingIndicator: "<img src='_layouts/images/REFRESH.GIF'/>",
            debug: true
        });

Is there anything wrong in my CAML ?

Thanks

Rajdeep

 

Jun 14, 2011 at 12:23 PM

The CAML is definitely the problem.  It should probably resemble something like this:

<Query>
	<Where>
		<And>
			<Eq>
				<FieldRef Name='Status' />
				<Value Type='Choice'>High</Value>
			</Eq>
			<Or>
				<Eq>
					<FieldRef Name='Status' />
					<Value Type='Choice'>Prioritized</Value>
				</Eq>
				<Eq>
					<FieldRef Name='Status'/>
					<Value Type='Choice'>Active</Value>
				</Eq>
			</Or>
		</And>
	</Where>
</Query>

 

To make your life easy, download the U2U Caml Builder tool and let that do the work for you.

Jun 14, 2011 at 1:08 PM

Thank You so much for your quick reply. Yeah the problem was in the multiple OR condition. I changed it and it started working.

      var caml = "<Or><Or><Eq><FieldRef Name='Status' /><Value Type='Choice'>High</Value>"+

                 "</Eq><Eq><FieldRef Name='Status' /><Value Type='Choice'>Prioritized</Value></Eq>"+

                 "</Or><Eq><FieldRef Name='Status' /><Value Type='Choice'>Active</Value></Eq></Or>";

 

Now I am trying to make use of filterType : "Contains" instead of the default "BeginsWith". But doesn't seem to work :(

My function looks like below.

$().SPServices.SPAutocomplete({

                             

      WebURL: "/sites/MySite",

     sourceList: "List",

      sourceColumn: "ID",

      columnName: "ProjectNo",

      CAMLQuery: caml,

      filterType: "Contains",

      numChars: 3,

      ignoreCase: false,

      highlightClass: "",

      slideDownSpeed: "fast"

    });

 

Is there anything wrong in the filterType: "Contains" ?

Thanks

Rajdeep

 

Jun 15, 2011 at 7:22 AM

Can anyone tell me which event can be fired after I select a value from the auocomplete dropdown ? After I select a value from the AutoComplete dropdown I want to fire getlistitems to pull neccessary informations related to the item selected. I tried using Completefunc with autocomplete but didn't work.

Thanks

Coordinator
Jun 16, 2011 at 8:26 PM

You might want to look at SPDisplayRelatedInfo, as it does something similar to what it soind like you're trying to build.

You should be able to attach to the change event for the input element. If you check the documentation, there is no completefunc option for the SPAutocomplete function, mainly because you can simply attach to the change event easily.

M.