2

I have a calculated column that is made to be a link that links to the items own custom forms. The ID that is used to link to that item is done by a custom number field that is set by a workflow after an ID has been assigned.

99.99% of the time it works perfectly fine. Some times the ID is missing when the user clicks on the button. The link is still valid so the user is taken to the first item in the list (not the item they click on).

Not sure why or how to fix this. Any pointers are welcome as this problem seems to happen on other lists as well.

Example of the calculated column button code:

 ="<button class=""button""  
           onclick=""window.location"
  &CONCATENATE("='/Departments/Sales/Lists/Sales Activity Tracker/UpdateCustomer.aspx?ID="
               ,backend_ID
               ,"' ")
  &";"" style=""height:35px;"">Update Customer</button>" 

1 Answer 1

2

Note:

in June 2017, Microsoft disabled the use of JavaScript in a Calculated Column

That means given answers may not apply for newer SharePoint versions

For long explanation and work arounds see:
June 13th 2017 Microsoft blocked handling HTML markup in SharePoint calculated fields - how to get the same functionality back


Original answer:

The ID is available on the TR in the view, so you can extract it with JS and built the HTML dynamically

Your CC Formula will now mix HTML+JavaScript:

    ="<a href='#' onclick=""{PreventDefaultNavigation();"
    &"var ID=getItemIDFromIID(findIIDInAncestorNode(this)),"
    &"url='/Departments/Sales/Lists/Sales Activity Tracker/UpdateCustomer.aspx?ID=';"
    &"this.parentNode.innerHTML='Opening:'+ID;"
    &"window.location=url+ID;"
    &"}""><img src='/_layouts/images/VIEWREPORTSHH.png' width='20px'></a>"

MAYBE

This is the code for a button

    ="<button onclick=""{PreventDefaultNavigation();"
    &"var ID=getItemIDFromIID(findIIDInAncestorNode(this)),"
    &"url='/Departments/Sales/Lists/Sales Activity Tracker/UpdateCustomer.aspx?ID=';"
    &"this.parentNode.innerHTML='Opening:'+ID;"
    &"window.location=url+ID;"
    &"}""></button>"

I have not tested this. Be aware SharePoint itself adds a FORM to the page, so it captures BUTTON events. That is why onclick events on non-buttons are safer; they don't trigger SharePoints own code.

I replaced the (standard JavaScript) event.stopPropagation() with SharePoints PreventDefaultNavigation(); function, that might help with not triggering SP events
(again.. your mileage may very when using button)

ICC TOP20

3
  • Your code works great as is however I can't seem to edit it for it to become a button (maintain look and feel). If I wrap it in a button it fails and if I replace the image with a button tag it also fails?
    – Roland
    Commented Aug 5, 2016 at 0:15
  • 1
    Because a BUTTON inside an A is invalid HTML. Commented Aug 5, 2016 at 7:48
  • Ah my bad, thanks for updating your answer. Seems to be working as intended.
    – Roland
    Commented Aug 7, 2016 at 23:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.