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

I'm looking to create a SP site that will primarily be used to pull up inventory items, as an adjunct to a separate not-SP app in our org. Imagine a list "Items", where there is a part number field which is a not-numeric single line of text, and other fields for a description, etc.

What I need to do is to be able to pull up an item from the list by part number, in the URL. E.g., mysite/item.aspx?myPartNumber=A-12345.

How would I best go about accomlishing this?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

I'm not 100% certain that I understand your question... My approach would be to use the CEWP and pull the data with JavaScript. You could have an element on your page that contains the user entered part number and returns info regarding the part.

What I can show you is how to pull list entry items from lists within your site collection using a SOAP envelope in conjunction with a lists webservice call. The returned values can be addressed using JavaScript to create any kind of HTML table that you like. I've been working on this code myself for the past two weeks. I hope that it is of use:

<script type="text/javascript">
if (!window.console) console = {log: function() {}}; </script>
<script language="javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js " type="text/javascript"></script>
<script type="text/javascript">

$(document).ready(function() {
z=0;
    GetFile();
    function GetFile(){
        var soapEnv =
            "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
                <soapenv:Body> \
                     <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                        <listName>Parts</listName> \
                            <ViewFields> \
                               <FieldRef Name='PartNumber' /> \
                           </ViewFields> \
                    </GetListItems> \
                </soapenv:Body> \
            </soapenv:Envelope>";
        $.ajax({
            /*Note that this is an ABSOLUTE lists webservice call. 
            You must point at the target site which houses the list
            you are trying to manipulate */
            url: "https://mydomain.com/warehouse/bitest/_vti_bin/lists.asmx",
            type: "POST",
            dataType: "xml",
            data: soapEnv,
            success: function(xData, status) {
                var PartNumberArray = [];
                i=0;
                //You must parse the returned string as XML to ensure that IE can access
                xmlDoc = $.parseXML(xData.xml); 
                $(xmlDoc).find("z\\:row").each(function() {
                   PartNumber[i] = parseFloat($(this).attr("ows_PartNumber"));
                   i++;
                   $("#tasksULa").append(PartNumber[i].toString());
                   });
                 //HERE you can work to winnow out the part number you are looking for
                //You will need to pull the value of the target part number from an element within another div on the page or CEWP


            },
            error: function (xhr, ajaxOptions, thrownError){
                //This function throws an error and retries if the call is not successful
                 z++;
                 alert(xhr.status);
                 alert(thrownError);
                 setTimeout(GetFile(), 5000);
                 console.log("Error " +z+": " + thrownError);
            },
            contentType: "text/xml; charset=\"utf-8\"",
            async: false
        });
    };

});</script><ul id="tasksULa"></ul>

Particular fields to pay attention to:

  • FieldRef Name
  • listName
  • URL field in the AJAX method
  • Value in the .attr field in the XML iterator

As a sidenote I modified this code and pasted it directly; no guarantees that it is 100% bug free. Again, I hope this meets your needs.

EDIT & UPDATE Also use this code to pull a full xml file based on your target list. All you need is the parent site URL and the list GUID. Use this code inside of a CEWP and it will build the target URL for you. I.E. just stick the components in the textboxes, click the button and then use the resulting URL to get the XML doc:

<script type="text/javascript">

//This is the target format for the XML request
//{SITEURL}/_vti_bin/owssvr.dll?Cmd=Display&List={GUID}&XMLDATA=TRUE&Query=*
function buildTargetXMLURL() {
   var XMLURL = "";
   XMLURL = document.getElementById("SiteURL").value + "/_vti_bin/owssvr.dll?Cmd=Display&List=" + document.getElementById("ListGUID").value + "&XMLDATA=TRUE&Query=*";
document.getElementById("TargetURL").value= XMLURL;
}
</script>
 Parent Site URL: <input id="SiteURL"/><br/>List GUID: <input id="ListGUID"/> <br/><br/>Target URL: <input id="TargetURL"/><br/><button onclick="buildTargetXMLURL()">Get XML URL</button>
share|improve this answer
    
Thank you! Your code allowed me to get a peek at the list data, so now it should be a case of calling the correct methods against the list. –  Alan M Aug 22 '12 at 19:57
    
@Alan M I'm glad that it helped! It's been my labor of love for the past 2 weeks. I updated the answer with a codeblock that you can use in a CEWP to pull the full xml version of the list. Also check out ListData.svc service calls using WCF. I'm trying to figure it out now (see my question regarding it) as I think it could be far easier than using CAML queries with SOAP requests. –  Shrout1 Aug 22 '12 at 20:41
    
I have read the instructions for formatting code in a comment. THEY DON'T WORK. Anyhow, here is how I had to code the GetListItems bit to query a single item: In order to query for a single item "1-00003": <GetListItems xmlns='schemas.microsoft.com/sharepoint/soap/'>; \ <listName>NavItems</listName> \ <query><Query> \ <Where> \ <Eq> \ <FieldRef Name='LinkTitle' /> \ <Value Type='Text'>1-00003</Value> \ </Eq> \ </Where> \ </Query></query> \ <queryOptions><QueryOptions/></queryOptions> \ </GetListItems> \ –  Alan M Aug 23 '12 at 18:41
    
Yeah it's annoying to add code in a comment. I will typically edit my original question and make a note that I updated it. The original question supports full coding. You can use the "backtick" symbol (the key above "Tab" on the keyboard - NOT the ~ symbol, but the other one) before and after code in a comment to have it highlighted. Also, you should be able to "build" that CAML query by adding your part number into the string in between <Value Type='Text'>. Would look a little like "...<Value Type='Text'>" + PARTNUMBERVARIABLE + "</Value> \..." –  Shrout1 Aug 23 '12 at 19:47

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.