0

I'm trying to grab data from an external list using ecmascript. I'm running into a slight problem. I'm not getting an error popup, however, in debugger mode it's referencing the above error message and the code halts at that line.

<SharePoint:ScriptLink Name="MicrosoftAjax.js" runat="server" Defer="False" Localizable="false"/>
<SharePoint:ScriptLink Name="SP.core.js" runat="server" Defer="False" Localizable="false"/>
<SharePoint:ScriptLink Name="SP.js" runat="server" Defer="True" Localizable="false"/>
<SharePoint:FormDigest ID="MyFormDigest" runat="server"/>
<script language="javascript" type="text/javascript" src="/Scripts/jquery-1.11.0.min.js"></script>
<script language="javascript" type="text/javascript" src="/Scripts/jquery.SPServices-2014.01.min.js"></script>
<script language="javascript" type="text/javascript">

//_spBodyOnLoadFunctionNames.push(""); 
ExecuteOrDelayUntilScriptLoaded(OnLoad, "sp.js");

function OnLoad()   
{   
    // Grab parent link id number and Request number
    var varitem;
    var itemID = $("#ctl00_m_g_32d59762_da31_442a_8334_da53c330611c_FormControl0_V1_I1_S7_I1_H1").text();
    var RequestNum = $("#ctl00_m_g_32d59762_da31_442a_8334_da53c330611c_FormControl0_V1_I1_T4").val();
    GetItemByID();

    function GetItemByID()
    {
        var context = new SP.ClientContext.get_current();
        var web = context.get_web();
        var list = web.get_lists().getByTitle('Contract Work Requests');
        alert(itemID);
        this.varitem = list.getItemById(itemId);     <<<<<====== Debugger stops here

        alert(RequestNum);
    }


}   // End OnLoad
</script>

I thought this line was defining it..... Any assistance in getting past this error would be welcome and appreciated. Thanks.

var itemID = $("#ctl00_m_g_32d59762_da31_442a_8334_da53c330611c_FormControl0_V1_I1_S7_I1_H1").text();
  • Go to your page with this particular form, open your browser dev tools and enter in the var itemId = $... line but leave off the .text() ending -- does the assignment find a jQuery DOM element or not? – John-M Dec 8 '14 at 2:50
  • I copied and pasted the entire var itemID line minus the .text() suffix and dropped it into the search bar (of dev console) in my Firefox Dev edition browser. Not sure if that's what you meant. It didn't find a dom element, however, the alert(itemID) code line does return the correct information when I load the form. The particular element in question is a hyperlink... – Ghoztrider Dec 9 '14 at 17:06
  • I meant the javascript console "Browser Console command line": developer.mozilla.org/en-US/docs/Tools/Browser_Console -- and if you're using the exact script you've posted above you mis-typed the variable name: it should be this.varitem = list.getItemById(itemID); not itemId (case-sensitive) – John-M Dec 9 '14 at 17:21
  • BAAHHH....That was it, the mispelling. Captain obvious I am NOT! Thanks for pointing that out to me John! – Ghoztrider Dec 9 '14 at 17:50
  • I did also take a look at the console as well. Thanks for the tip... – Ghoztrider Dec 9 '14 at 17:51
0

You initialized the variable as itemID

var itemID = $("#ctl00_m_g_32d59762_da31_442a_8334_da53c330611c_FormControl0_V1_I1_S7_I1_H1").text();

But called it with itemId

this.varitem = list.getItemById(itemId);

It's easy to overlook! But Javascript is case-sensitive, so you'll need

this.varitem = list.getItemById(itemID);

As discussed in the comments :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.