Author Topic: Edit Info Fields tool Script question  (Read 2606 times)

0 Members and 1 Guest are viewing this topic.

Padanges

  • Newbie
  • *
  • Posts: 179
Edit Info Fields tool Script question
« on: August 17, 2016, 11:04:57 AM »
Hi,
I would to create a script which looks similar to this:

function TestSwitch() {
switch (CurrentField.Value) {
   case '1': {
            return 1 // change values to 1
            }
            break;
   default:
            break;  // do nothing -- leave values unchanged
}
}

and after using [TestSwitch](2) I would like to have column values unchanged (because I create a break after default/otherwise statement) but i get all values set to "". Any ideas why is that so? Is there a way to create an escape from column value changes?

RTT

  • Administrator
  • *****
  • Posts: 907
Re: Edit Info Fields tool Script question
« Reply #1 on: August 18, 2016, 01:01:22 AM »
The tool always replace the function call tag, in the expression, by its result. Returning nothing is not a condition, and can't be, to not change the expression result or discard the use of it.
The best way to accomplish this is by passing also the effective current field value as parameter. Let's say you are using the TestSwitch in the Title field. You may write the expression as: [TestSwitch](2,[T])
And change the script to:
Code: [Select]
function TestSwitch() {
    var optionID = CurrentField.Value.substr(0, 1);
    switch (optionID) {
    case '1':
        {
            return 1 // change values to 1
        }
        break;
    default:
        return CurrentField.Value.substr(2); //returns field original value
    }
}