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> 
2
  • 1
    I think internal name of Name column in SharePoint document library is FileLeafRef try using this :) Commented May 3, 2018 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. Commented May 3, 2018 at 13:04

1 Answer 1

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.

1
  • @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. Commented May 3, 2018 at 13:08

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.