2

I'm building a simple app on a SP2013 online intranet that uses the Google Books API to pull in GB content (title, author, image etc). The goal is to modify a SP list view to populate the book isbn using a jslink file, so the correct book gets rendered. My custom item line looks like this but doesn't work:

var ret = "<script>var googleAPI = 'https://www.igoogleapis.com/books/v1/volumes?q=" + ctx.CurrentItem.Book_x0020_id + "';></script>";
return ret; 

Is it even possible to include a script variable declaration within a jslink file? Another option would be to use a calculated field instead, but SP encodes some of the html causing the script to break.

0

This article is probably what you're looking for. It suggests to create 2 ‘single line of text’ columns with JavaScript and 1 calculated column to put everything together.

Using JavaScript URL in Calculated Columns

  • Also, that article seems to be addressing syntax issues with inline scripts (quotation marks). This is really about getting a variable to function. Everything needed shows up correctly using either method when I inspect the output but nothing gets rendered. Any other thoughts on how this might be done? – matt Jan 21 '16 at 23:06
0

I would say it's not possible. You can include multiple files within JSLInk by using | between the JSLink property in Web Part settings, e.g., ~site/myscript.js|~site/myotherscript.js, and myscript.js would be usable in myotherscript.js. It doesn't, however support any variables, so it will not work in you case.

Could you make AJAX call to that Google API from within your main JSLink file?

  • That's a good idea but I'm not sure how I would do that within jslink. – matt Jan 21 '16 at 23:01
0

It turns out pulling the calculated column in using a content query web part works. I added the field ref name in the description box of a cqwp and - bingo.

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.