Rollbase - JavaScript functions in Triggers

Posted by araqiel on 07-Jul-2014 03:19

Hello,
Is it possible in Rollbase to insert Javascript functions in Triggers ?
I would try it, but not functional.
When I put key-word "function" an error was report.

Thanks,

Posted by Santosh Patel on 08-Jul-2014 03:58

The basic difference between a field update trigger and an object script trigger would be the former expects a value back. Your code would only seem logical but Rollbase norms require that it be of the following format

var myVar = setMyVar();

function setMyVar() {
  return "Toto";
}

myVar;


Notice no "return". Update field value triggers expect a value back (you don't need return here) while object script triggers just execute code and have a void return. 

I hope this answers your question on either of the trigger types.

Regards,
Santosh

All Replies

Posted by Mani Kumar on 07-Jul-2014 03:42

Hi,

This should be possible in Triggers.

Could you please share the sample code that you are trying and the details of the trigger?

Regards,

Mani.

Posted by pvorobie on 07-Jul-2014 11:45

You can use JavaScript in many trigger types, including:

- in "Update Field Value" to calculate new field's value

- in "Object Script" to run any script, which usually includes server-side APIs to manipulate data

Posted by araqiel on 08-Jul-2014 03:34

Hi,

My sample code.

var myVar = setMyVar();

function setMyVar() {
   return "Toto";
}

return myVar;

 


When I add return value, the code is broken.

Posted by Santosh Patel on 08-Jul-2014 03:58

The basic difference between a field update trigger and an object script trigger would be the former expects a value back. Your code would only seem logical but Rollbase norms require that it be of the following format

var myVar = setMyVar();

function setMyVar() {
  return "Toto";
}

myVar;


Notice no "return". Update field value triggers expect a value back (you don't need return here) while object script triggers just execute code and have a void return. 

I hope this answers your question on either of the trigger types.

Regards,
Santosh

Posted by araqiel on 08-Jul-2014 07:10

I have always used "return" for Update field value triggers. But I would like use functions and an error was reported.

Now, I know, no use return for this case.

Thank you Santosh. It's work !

Posted by pvorobie on 08-Jul-2014 12:18

You can also try

function setMyVar() {

 return "Toto";

}

setMyVar();

This thread is closed