0

I have a requirement to read the "Name" column in a SharePoint document library, tried many things but didn't really work. I am using below code to alert a lookup column and ItemID upon uploading a file in the library. Please see below screenshot for columns info on Document library.

enter image description here

When I checked the Internal Name of the Name column, it says: LinkFilename. Can someone help me how would I read the Name column field in the below code. THanks in advance.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(function () {
        $("#ctl00_ctl41_g_dbb46bd2_e248_49a1_b1b7_932ee0cf704c_ctl00_ctl02_ctl00_toolBarTbl_RightRptControls_ctl00_ctl00_diidIOSaveItem").click(function () {
            var entityid = $("select[title='Entity ID']").find("option:selected").text();
            alert(entityid);


            var itemID = getParameterByName('ID');
            alert(itemID);
            var docname =$('LinkFilename').val();
            alert(docname);
        });
    });

    function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
    results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}


</script>
  • 1
    I think internal name of Name column in SharePoint document library is FileLeafRef try using this :) – san May 3 '18 at 3:20
  • @sathish, i checked from the browser url and it says LinkFilename as of internal name. There are about 3-4 Name columns we get to work for SharePoint libraries. – mdevm May 3 '18 at 13:04
1

Why do you use the jQuery selector ($('LinkFilename')) to get the field value based on its internal name? The jQuery selectors are used to get elements from the page.

Get the item based on the item id using JSOM/CSOM with getItemById(id) function.

Some basic operations using JavaScript library code in SharePoint

Use “FileLeafRef” instead of “Name/LinkFilename” to get the file name from the item.

  • @JoannaW-MSFT, I already tried FileLeafref and Name using Jquery but that didn't work as well. I can't manually pass the ID and read the file name in my case. As you can see I am alerting a Lookup column value called Entity ID on click of a save button in the default edit form of a sharepoint library. So when someone uploads a document to the library I want to alert the file name of that file. Thanks again. – mdevm May 3 '18 at 13:08

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.