简体   繁体   中英

Sharepoint Online - Lookup field - Client side rendering

Essentially we are looking to use lookup values in a calculated column from another list called episodes in a list called workbook.

We could run scheduled list workflows using this -

https://plumsail.com/workflow-actions-pack/

Or getting someone to write a timer job.

I didn't really like these solutions and wanted something more dynamic then found this:

https://sharepoint.stackexchange.com/questions/128479/lookup-column-in-calculated-column-formula

Great Little hackaround by Danny. But struggled with re-purposing the code to see if i could get it show a lookup value from the list called episode.

Dannys code:

=" <img src=""/_layouts/images/blank.gif"" onload=""{"
    &"var TR=this.parentNode.parentNode.parentNode,"
    &"    item=ctx.ListData.Row[TR.rowIndex-1],"
    &"    discount=item.Vendor_x003a_Discount,"
    &"    price=item['Price.'];"
    &"console.log(discount,price,item);"
    &"this.parentNode.innerHTML=discount*price;"
&"}"">"

My Botched Version:

=" <img src=""/_layouts/images/blank.gif"" onload=""{"
  &"var TR=this.parentNode.parentNode.parentNode,"
  &"item=ctx.ListData.Row[TR.rowIndex-1],"
  &"deact=item.epslook_x003a_DeActTime,"
  &"console.log(deact,item);"
  &"this.parentNode.innerHTML=deact;}"">"

Tried the lookup name in workbook epslook:deActTime and episode:deActTime.

Where am I going wrong?

Sorry to redirect you again

You are now asking in the Generic StackOverflow Forum

https://sharepoint.stackexchange.com/ is a whole dedicated Forum, and that is the place where people expect SharePoint questions; I would never have seen this question had you not mailed me the link.


As for your problem, these code bits inside a Formula are very very very hard to debug. You have to build them step by step

Disclaimer: I have not tried the code below, so there could be typos!!

1

=" <img src=""/_layouts/images/blank.gif"" onload=""{"
    &"var TR=this.parentNode.parentNode.parentNode,"
    &"    item=ctx.ListData.Row[TR.rowIndex-1];"
    &"console.log(item);"
&"}"">"

This should work, if not.. Houston we have a problem

The console should now get you the exact name of the variable you are after

2

=" <img src=""/_layouts/images/blank.gif"" onload=""{"
    &"var TR=this.parentNode.parentNode.parentNode,"
    &"    item=ctx.ListData.Row[TR.rowIndex-1];"
    &"console.log(item.epslook_x003a_DeActTime);"
&"}"">"

3

Now note that in your version your JavaScript is wrong. You are mixing declarations and statements because of improper , and ; use

So we simplify (and write longer code) to try and prevent mistakes (note the , became a ;)

=" <img src=""/_layouts/images/blank.gif"" onload=""{"
    &"var TR=this.parentNode.parentNode.parentNode;"
    &"var item=ctx.ListData.Row[TR.rowIndex-1];"
    &"console.log(item.epslook_x003a_DeActTime);"
&"}"">"

4

So (if the item key is correct) this should work:

=" <img src=""/_layouts/images/blank.gif"" onload=""{"
    &"var TR=this.parentNode.parentNode.parentNode;"
    &"var item=ctx.ListData.Row[TR.rowIndex-1];"
    &"var deact=item.epslook_x003a_DeActTime;"
    &"console.log(deact,item);"
    &"this.parentNode.innerHTML=deact;}"">"

Where you had written: ( You are trying to declare a console statement as a variable )

=" <img src=""/_layouts/images/blank.gif"" onload=""{"
    &"var TR=this.parentNode.parentNode.parentNode,"
    &"item=ctx.ListData.Row[TR.rowIndex-1],"
    &"deact=item.epslook_x003a_DeActTime,"
    &"console.log(deact,item);"
    &"this.parentNode.innerHTML=deact;}"">"

5

Once you know it works.. you can.. carefully!!!.. make the code smaller

=" <img src=""/_layouts/images/blank.gif"" onload=""{"
    &"var TR=this.parentNode.parentNode.parentNode;"
    &"this.parentNode.innerHTML=ctx.ListData.Row[TR.rowIndex-1].epslook_x003a_DeActTime;}"">"

Also note there are more SharePoint helper functions.

I have added the ICC text-tag to all interesting StackExchange Answers that use this HTML/JS in a Calculated Column:

https://sharepoint.stackexchange.com/search?tab=votes&q=ICC

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM