SharePoint 2013 Calculated Field not working all the time

sharepointsharepoint-2013sharepoint-designersharepoint-workflow

I have a form where I need to include a calculated field. I made a very simple test using a calculated field where the formula is "=ID". I just want to confirm that the value I'm getting in the view is the same as the ID of the record in the list.

I press NEW and create a new record. Then when I see the new record in the view, the first column is the ID (let's say 11), then some proper fields form the form and finally the calculated field that instead of showing me the value 11, it shows 0.

Then I follow the following steps:

  1. I go to Settings, List Settings
  2. Click on the calculated field to edit it (only edit it with no modifications) and press on OK (no modifications to the calculated field at all)
  3. Go back to the list of records and now the calculated value shows me the value 11

I google it but no solution.. there is someone say that this issue is from the column ID, it mean 'when you initially save the item is that there is no value for "ID" yet' !
and this isn't my state, the column id is incremented normally when add new item.

Anyone can help me to identify with the calculated field does not shows 11 automatically after the record is saved?
or by follow another solution like using a workflow 2013..

Thanks a lot

Best Answer

You can not use [ID] in a Calculated Column formula. I won't bother with the long technical explanation...

If it was possible, Microsoft would have added it to the list of Fields you can select when writing a Formula.

Workaround is to make a simple SharePoint Designer Workflow which kicks off on Item creation and saves the ID value to another Column.

You can then use that Column in your Calculated Formulas

If you're doing anything front-end.. jQuery.. CSR/JSlink.. the ID value is available in the attribute id of the Item TableRow (TR) as x,id,y so you can get the id with

var ID={element}.getAttribute('id')[1]

Update #1 - example code used:

="<a href='/sites/ru1/Lists/ao26c/DispForm.aspx?ID=' 
     target='_blank'><img src= '_layouts/images/blank.gif' 
     onload= ""var row=this;
               while(row.tagName!='TR'){row=row.parentNode};
               this.parentNode.href+=row.‌​getAttribute('id').split(',')[1];
             "">Открыть</a>"
Related Topic