We’ve developed some resources to help you work effectively from home during COVID-19 Click to learn more

CRMScript: developerMode=true for testing

Hi all,

Just a small note about a very small feature just implemented. I have been working with some CRMScript modules, and what was bugging me was that since the modules only have functions (no global code), you cannot click the "Execute" button to test them. If you include global code, it will get executed every time the library is included in a script, which obviously is not what you want.

So, I have added two environment variables (available using getVariable(...)) which are only set when the script is executed using the "Execute script" button in the "Edit script" screen:

  • "developmentMode": "true"
  • "includeId": the includeId of the current script (to prevent this from getting executed when testing other modules)

This allows you to include some global code in your CRMScript like this:

if (getVariable("developmentMode") == "true" && getVariable("includeId") == "myLibrary")
{
  printLine(myFunction("Hello world"));
}

So, when editing your library, you can click the "Execute script" button and this part will be executed, printing out whatever your function does. When this library is included in some other production code and executed, the code above will not be executed. Hopefully, you will find this useful :) It will become available in 8.5R08.

Sverre

RE: CRMScript: developerMode=true for testing

Nice, that will be useful.

If you create a generic script called "lib-developermode" as well, then the code could be simplified a little like this:

//Script: "lib-developermode"

Bool developerMode(String includeId) 
{
  return (getVariable("developerMode").toBool() && getVariable("includeId") == includeId);
}

And then in you other scripts you can do this:

//Script: example-functions

#setLanguageLevel 3;
#include "lib-developermode";

String reverse(String text)
{
  //todo
}

if (developerMode("example-functions"))
{
  assert(reverse("FooBar") == "raBooF");
}
Av: Frode Lillerud 1. nov 2019

RE: CRMScript: developerMode=true for testing

Is it "developerMode" or "developmentMode"?

Av: Frode Lillerud 1. nov 2019

RE: CRMScript: developerMode=true for testing

Hi,

Looks like it is "developmentMode" as Sverre stated in his post.

 

 

Av: Michel Krohn-Dale 1. nov 2019

RE: CRMScript: developerMode=true for testing

Allright, just asking since forum thread title says 'developerMode'.

Av: Frode Lillerud 1. nov 2019