I am hoping this helps someone else as well and save the hours I did hunting for this.
I have a document library with a URL column as well. I needed the URL to each file and the URL string in my URL column. I accomplished this with these properties:
var objUrl = listItem.get_item('UrlLink')
var FileNameFull = listItem.get_item('FileRef').toString();
Full Code:
<script type="text/javascript">
//
//Call when Client OM is ready
ExecuteOrDelayUntilScriptLoaded(ReadListItems, "sp.js");
//Main Code to retrive Document Library Data (List Data)
function ReadListItems() {
var listTitle = 'GridAnnouncements'
//get the current client context
context = SP.ClientContext.get_current();
var gridItems = context.get_web().get_lists().getByTitle(listTitle);
var camlQuery = SP.CamlQuery.createAllItemsQuery(); //PreDefined CAML Query to get all items in List/Document Library
this.listItems = gridItems.getItems(camlQuery);
context.load(listItems);
//Run the query on the server
context.executeQueryAsync(onQuerySucceeded, onQueryFailed);
}
//Success CallBack
function onQuerySucceeded(sender, args) {
var itemString = '';
var enumerator = listItems.getEnumerator();
while(enumerator.moveNext()){
var listItem = enumerator.get_current();
itemString += 'name: ' + listItem.get_item('Title').toString() + '\n'; // for some reason \n works like <br /> on test page
try{
var objUrl = listItem.get_item('UrlLink')
var FileNameFull = listItem.get_item('FileRef').toString();
//alert( str ) ;
itemString += 'FileUri: ' + FileNameFull.toString() + '\n';
itemString += 'LinkUrl: ' + objUrl.get_url() + '\n' + '\n';
}
catch (err)
{ alert(args);} //primative debugging.. then again I am using SharePoint Designer
}
document.getElementById("HeaderContent").innerText = itemString;
}
//Failure CallBack
function onQueryFailed(sender, args) {
alert('request failed ' + args.get_message() +
'\n' + args.get_stackTrace());
}
</script>
I would love to know it helped someone!