మంత్లీ ఆర్కైవ్స్: ఫిబ్రవరి 2014

ఒక శోధన స్కోప్ వంటి ప్రజలు పేర్కొనండి / కంటెంట్ మూల ఉపయోగించి SharePoint 2013 REST API

I had reason to work with the SharePoint 2013 Search API via REST for the first time. I wanted to search for people, not documents. The key learning here is that you specify content sources via its GUID (or at least in this case). The following jQuery snippet shows how:

    loadExpertsAsync: ఫంక్షన్() {

        jQuery.support.cors = నిజమైన;

        $.ajax({
            url: .CreateFullApiUrl() +
                "?querytext='portals'&sourceid='b09a7990-05ea-4af9-81ef-edfab16c4e31'" +
                "&selectproperties='LinkedInProfileUrl,GoogleCirclesProfileUrl,BALargeProfilePictureUrls,BAGridPictures,WorkEmail,Skills,AboutMe,Interests,JobTitle,PastProjects,PictureURL,PreferredName,TwitterHandle,LinkedInProfileUrl,PreferredName,GoogleCirclesProfileUrl'" +
                "&rowlimit=99",
            పద్ధతి: "GET",
            headers: { "Accept": "application/json; odata=verbose" },
            cache: అబద్ధమైన,
            success: ఫంక్షన్ (ఫలితంగా) {

నా విషయంలో, I’m running the API against SharePoint online. To get the GUID, I followed these steps:

  1. Access the SharePoint admin center
  2. Select “search” from the left hand navigation
  3. Select “Manage Result Sources”
  4. Select “Local People Results”
  5. Look at the URL.

My URL looked something like:

https://xyzzy-admin.sharepoint.com/_layouts/15/searchadmin/EditResultSource.aspx?level=tenant&sourceid=b09a7990%2D05ea%2D4af9%2D81ef%2Dedfab16c4e31&view=1

The sourceid parameter is what worked for me.

(I understand that the sourceid may actually be a sort of permanent thing with SP, but I’ll always check anyway 🙂 ).

</చివర>

undefinedనా బ్లాగ్ సబ్స్క్రయిబ్.

వద్ద ట్విట్టర్ లో నన్ను అనుసరించండి http://www.twitter.com/pagalvin

ఉదాహరణ SharePoint REST కాల్స్

Here’s a set of sample REST calls that work for me and may help you out as well. నాటికి 02/2014, there are two examples 🙂

  1. Reference a Column With Spaces In Its Name
  2. Reference a Multi-Select Column
  3. Perform a People Search via REST

 

I’ll add to this as time passes.

Here are some useful inks I’ve found as well:

Reference a Column With Spaces In Its Name

I create a custom list with a column named “Blog Author” (space between Blog and Author).

The $select to reference that column is:

image

Simply replace the space with “_x0020_”. We see the _x0020_ in many examples across the internets and REST is no different.

If you don’t do that, you’re liable to get an error message like this:

The expression “Blog Author” is not valid.

Easy enough.

Reference a Multi-Select Lookup Column

Set up:

  1. Create a custom list named Categories.
  2. Add some categories. I added categories thusly:image
  3. Create another custom list called MockBlog and add Categories as a multi-select list column (or site column if that’s how you roll).

Add some items to your Mockblog list and you’re ready.

An Ajax style call using jQuery will look something like this:

serverUrl  = "/_api/web/lists/GetByTitle('MockBlog')/అంశాలు" +
             "?$select=Title,Categories/Title,Blog_x0020_Author/Title" + 
             "&$expand=Blog_x0020_Author,Categories";

We’re telling SharePoint “Give me the title for all the Categories (Categories/Title). Get the actual values for శీర్షిక వలన $expanding the Categories list.” (My RESTful paraphrasing is probably pretty loose, but this how I’m interpreting it).

If you’re doing this via JavaScript and using Fiddler to look at the output, you get something like this in return:

 

image

(The above is a JSON object)

Perform a People Search via REST

I blogged about this separately. The key is to specify a sourceid parameter whose value is the GUID of the Local People content source. (Content sources used to be called scopes and it’s my-oh-my so hard not to call everything a scope for me!).

దాని గురించి మరింత ఇక్కడ చదవండి: http://www.mstechblogs.com/paul/?p=10385

 

</చివర>

undefinedనా బ్లాగ్ సబ్స్క్రయిబ్.

వద్ద ట్విట్టర్ లో నన్ను అనుసరించండి http://www.twitter.com/pagalvin

త్వరిత మరియు సులువు: REST ఉపయోగించి ఒక SharePoint సైట్ సృష్టించు

There are a lot of resources around that show how to do this, but I couldn’t find a comprehensive go-to link, so here we are.

You can create a SharePoint site using the REST API.  Here’s a fully baked example:

<!--
    SiteRequestForm.html: Collect information and create a site for the user.
-->

<సెంటర్>
<పట్టిక>
    <tr>
        <td>Site Name:</td>
        <td><ఇన్పుట్ రకము="text" పేరు="SiteName" ID="SiteName" /></td>
    </tr>
    <tr>
        <td colspan="2">
            <ఇన్పుట్ రకము="submit" ID="CreateSiteButton" విలువ="Create the Site" />
        </td>
    </tr>
</పట్టిక>
</సెంటర్>

<లిపి src="../Plugins/jquery-1.11.0.min.js"></లిపి>

<లిపి>
ఉంది CreateSiteLogicContainer = {

    createSiteData: {
            "parameters": {
                __metadata: { "type": "SP.WebInfoCreationInformation" },
                Url: "Paultest1",
                శీర్షిక: "Paultest1",
                వర్ణన: "rest-created web by Paul!",
                భాష: 1033,
                WebTemplate: "sts",
                UseUniquePermissions: అబద్ధమైన
            }
    },

    createSite: ఫంక్షన్ () {

        jQuery.support.cors = నిజమైన;

        CreateSiteLogicContainer.createSiteData.parameters.Url = $("#SiteName").Val();
        
        $.ajax({
            url: "https://bigapplesharepoint.sharepoint.com/NBAIADev/_api/web/webinfos/add",
            పద్ధతి: "POST",

            headers: {
                "Accept": "application/json; odata=verbose",
                "content-type": "application/json;odata=verbose",
                "X-RequestDigest": $("#__REQUESTDIGEST").Val()
            },

            డేటా: JSON.stringify(CreateSiteLogicContainer.createSiteData),

            success: ఫంక్షన్ () { హెచ్చరించు("success"); },
            తప్పు: ఫంక్షన్ () { హెచ్చరించు("error"); }

        });
    },

    wireUpForm: ఫంక్షన్ () {
        $("#CreateSiteButton").క్లిక్(ఫంక్షన్ () {
            హెచ్చరించు("About to try and create the site.");
            CreateSiteLogicContainer.createSite();
        });
    }


}

CreateSiteLogicContainer.wireUpForm();

</లిపి>

When successful, you get a JSON packet in response like this:

image

My key thoughts and learnings from this include:

  • This approach uses jQuery.  నా విషయంలో, my jQuery library is located in “../plugins.”  You’ll want to change that to point to your favorite JQ location.
  • You can copy and paste that whole snippet into a Content Editor Web Part on a page and it should work just fine.  You’ll want to change the end point of the API call and make sure you reference JQ correctly.
  • The URL is relative to your API’s endpoint.  నా విషయంలో, it’s creating sub-sites underneath https://bigapplesharepoint.com
  • You don’t need to provide a content-length. Some blog posts and MSDN document implies that you do, but happened for me automatically, which I assume is being handled by the $.ajax call itself.
  • This line is required in order to avoid a “forbidden” response: "X-RequestDigest": $("#__REQUESTDIGEST").Val().  There are other ways to do it, but this is pretty nice.  I have lost the link to blog that provided this shortcut.  H/T to you, mysterious blogger!

Good luck and hope this helps someone out.

</చివర>

undefinedనా బ్లాగ్ సబ్స్క్రయిబ్.

వద్ద ట్విట్టర్ లో నన్ను అనుసరించండి http://www.twitter.com/pagalvin

SharePoint క్విక్ లాంచ్ సాపేక్ష URL లు తో బాధించే సమస్య అధిగమించడానికి

I wanted to add a link to the quick launch navigation the other day and SharePoint told me:

image

Pure text version of that is:

Ensure that the URL is valid and begins with either a valid character (a number sign (#) or forward slash (/)) or a valid supported protocol (ఉదాహరణకు, ‘http://', ‘https://', ‘file://', ‘ftp://', ‘mailto:', ‘news:').

“Blech and pox!” I said.

A workaround to this is to use JavaScript to find a known link in the quick launch and override its behavior.

To test this, add a new link to your test site thusly:

image

I used jQuery. దీనిని పరిష్కరించడంలో, get some JavaScript and jQuery onto the page using your favorite technique and with a line of code like this:

 

$(పత్రం).సిద్ధంగా( ఫంక్షన్ () {

    $("ఒక:contains('Test URL replacement')").క్లిక్(ఫంక్షన్ () { హెచ్చరించు("changed click behavior!"); తిరిగి అబద్ధమైన;});

});

And Bob’s your uncle.

The jQuery selector finds every <ఒక> tag that has “Test URL replacement” in its name. You may want to find-tune that depending on your link and such.

The .click(ఫంక్షన్() overrides whatever SharePoint would have done when the user clicked. Make sure you “return false” or else it will do your stuff and then try to the href thing too, which is almost certainly not your goal.

This was done and test in a SharePoint online environment but should work well in 2010 and earlier too.

</చివర>

undefinedనా బ్లాగ్ సబ్స్క్రయిబ్.

వద్ద ట్విట్టర్ లో నన్ను అనుసరించండి http://www.twitter.com/pagalvin

త్వరిత మరియు సింపుల్: SharePoint REST కాల్ మాత్రమే రిటర్న్స్ 100 రికార్డ్స్

I’ve been working on a public facing web site for my SharePoint practice here in New York and it uses a lot of JavaScript and REST calls to show content.

During mainline development, I create a small dataset with just 10 or so rows in a custom list and my REST calls all pulled from there.  Once I bumped up the list to have a few hundred rows of data to test for anticipated growth, I found that I was getting exactly 100 rows returned back on my REST calls.

This is a very simple thing to address.  నా విషయంలో (and I believe in most cases), the default REST calls to SharePoint (and possibly as an industry standard?) తిరిగి 100 rows.  To return more than the default, use the $top parameter on your call, లో:

GET /Insights Dev/_api/web/lists/GetByTitle(‘MockBlog’)/అంశాలు?$select=ID,శీర్షిక,Categories/Title,Blog_x0020_Author/Title,DatePublished,BlogSummary&$expand=Blog_x0020_Author,Categories&$filter=&$top=9999

I picked 9999 in this case since I know that growth-wise, there won’t be more than 200 or so rows added to this list in a year.  If it becomes ungainly, we can implement some paging down the road.

</చివర>

undefinedనా బ్లాగ్ సబ్స్క్రయిబ్.

వద్ద ట్విట్టర్ లో నన్ను అనుసరించండి http://www.twitter.com/pagalvin

త్వరిత మరియు సింపుల్: "చెల్లని URL పారామీటర్ పరిష్కరించండి” lists.asmx లో UpdateListItems తో సమస్య

When working with UpdateListItems via lists.asmx, it’s easy to generate the error:

Invalid URL Parameter.

The URL provided contains an invalid Command or Value. Please check the URL again.

You can get this error when you forget to include ID in the the list of fields to update.  ఈ, like a lot of these SP web services, is a bit counterintuitive since you need to include the ID in the ID attribute of the <Method> element.  And you’re not updated ID and probably never want to in the first place.

This SOAP envelope works:

<soapenv:ఎన్వలప్ xmlns:soapenv ='http://schemas.xmlsoap.org/soap/envelope/'>
  <soapenv:శరీరం>                      
    <UpdateListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>                     
      <రాలునట్టి>{C712E2EA-54E1-47AD-9D99-1848C7773E2F}</రాలునట్టి>                     
        <updates>                     
         <Batch OnError="Continue">
          <Method ID="1" Cmd="Update">
            <Field Name="CooperativeLock">locked!</ఫీల్డ్>
            <Field Name="ID">1</ఫీల్డ్>
          </Method>
        </Batch>                     
        </updates>                
      </UpdateListItems>             
  </soapenv:శరీరం>         
</soapenv:పైకాకితము>

If you strip out the ID field reference then you’ll get the annoying “Invalid URL parameter” message.

</చివర>

undefinedనా బ్లాగ్ సబ్స్క్రయిబ్.

వద్ద ట్విట్టర్ లో నన్ను అనుసరించండి http://www.twitter.com/pagalvin