JSON column formatting set variable

Brass Contributor

This is my first attempt at JSON.  Found this article: Quick SharePoint Approvals using list formatting JSON to set field values - michelcarlo.

 

But, how do I set a variable in JSON?

I'm trying to set value to a column [$CurrentNumber], then use the new value to set another column [$CurrentApprover] value.  For example, if the first approver approvers the item, currentNumber and currentApprover values should be the next  approver. 

Below code works, at this point, but hoping to make it shorter. 

"elmType": "button",
          "customRowAction": {
            "action": "setValue",
            "actionInput": {
              "ItemStatus": "Pending",
              "Status1": "=if([$CurrentNumber] == 1, 'Approved', [$Status1])",
              "CurrentNumber": "=[$CurrentNumber] + 1",
              "CurrentApprover": "=if([$CurrentNumber] + 1 == 1, [$Approver1.email], if([$CurrentNumber] + 1 == 2, [$Approver2.email], if([$CurrentNumber] + 1 == 3, [$Approver3.email], if([$CurrentNumber] + 1 == 4, [$Approver4.email], if([$CurrentNumber] + 1 == 5, [$Approver5.email], [$CurrentApprover])))))"

But, I can't figure out how to use variables in JSON.
For example: 
var newNumber = [$CurrentNumber] + 1, 
CurrentNumber = newNumber, 
CurrentApprover = if(newNumber == 1, [$Approver1.email], ...)

*Also need to find out if I can use Switch statement instead of If for CurrentApprover. 

0 Replies