I am using SP2013 on-premise. I have two document libraries. Some files in DocLibA have a relationship with DocLibB's documents. I would like to create a column in DocLibA and link to 0-1 files in DocLibB. So that when a user browse DocLibA's view, he can directly download the related document with a single click. I have tried to setup a lookup column to DocLibB's title column. But it just gives me a link to open listform.aspx page (/_layouts/15/listform.aspx?PageType=4&ListId=<5475cxxxxx. >) which shows the file's properties. I want to directly link to the document (i.e. /DocLibB/file.pdf). Could you please advice?5475cxxxxx.>
You could use some Client Side Rendering to change the URL from listform.aspx to the URL of the document. You can probably get the URL to the document from the context object.
Commented May 26, 2016 at 10:10 Do have any sample code? I can find sample querying single item but not for entire list view. Commented May 27, 2016 at 8:08 Added answer with sample code. Commented May 27, 2016 at 10:10Assume you have a column in your DocLibA view that is a single value lookup column to a column in DocLibB (it actually doesn't matter which column in this case).
You can use Client Side Rendering to change the default link, which is to the display form of the item in DocLibB, to the item itself.
Place this code on the view page of DocLibA. The only change you need to make is to the name of the lookup column YourLookupColumnInternalName :
SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", CSR_Setup); function CSR_Setup() < var overridectx = <>; overridectx.Templates = <>; overridectx.Templates.Fields = < "YourLookupColumnInternalName": < "View": CSR_AddLinkToFile >>; SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overridectx); > function CSR_AddLinkToFile(ctx) < return String.format("'> ", ctx.CurrentItem.FileRef, ctx.CurrentItem.FileLeafRef); >