Upcoming CRMScript / Developer improvements

Av Michel Krohn-Dale, Uppdaterad på 8. jun 2022
push_pin
star

Dear community,

We have done some improvements to CRMScript upcoming release that we hope will be useful for you. The changes can be split into two main areas: improvements to CRMScript and improvements to the developer UI.


CRMScript improvements


For a few years now, we have had support for serializing/deserializing arrays and structs to JSON data. However, the support had some "gaps" in support for all basic types, and also the usage was a bit cumbersome having to go through XMLNode or JSONBuilder. To solve the latter, we have now introduced two new functions on arrays and struct: fromJsonString() and toJsonString(). The functions will allow you to serialize/deserialize in one swift code line:

struct Person {
  String firstname;
  String lastname;
  Date dob;
};

Person p;
p.fromJsonString('{"firstname": "Jon", "lastname": "Doe", "dob": "1984-10-26"}');
printLine(p.toJsonString());

The observant amongst you will perhaps also notice that in the code above, we are deserializing and serializing a member of type Date. This was not supported before, but now we actually support members of all basic types: Integer, String, Bool, Float, Date, Time, DateTime, Byte, TimeSpan. For the types not supported natively by JSON, we will require/produce the following formats:

  • Date: converted to/from string with format "YYYY-MM-DD"
  • DateTime: converted to/from string with format "YYYY-MM-DDTHH:MI:SS"
  • Time: converted to/from string with format "HH:MI:SS"
  • Byte: converted to/from number.
  • TimeSpan: converted to/from number (seconds)

Support for these additional types also work for the existing fromXMLNode() and toJson() methods.

Also, please note that fromJsonString() on arrays will work just like fromXMLNode(), which means it will append elements to the array and not clear it. Arrays have a separate .clear() method that can be called if you want to empty it first.

Furthermore, we have introduced two new methods on arrays: buildString() and sort()buildString(String separator) is adding some functionality that has always existed on Vector; the possibility to create a string (with a separator) from an array. The function will work as expected on basic types. (Complex types (e.g. an array of HTTP instances) will just result in a string with "[complex]"). The most useful example is probably to get a comma-separated array of integers:

Integer[] arr;
for (Integer i = 0; i < 10; i++) 
  arr.pushBack(rand(0, 100));
printLine(arr.buildString(","));

In addition to basic types, we also support buildString() on arrays of structs. The default way to serialize a struct instance is to return its contents as a JSON string. However, there is now a way to override this by adding a member function with the following signature: String toString():

struct Person {
  String firstname;
  String lastname;
  
  String toString() {
    return this.firstname + " " + this.lastname;
  }
};

Person[] persons;
persons.fromJsonString('[{"firstname": "Mark","lastname": "Wahlberg"}]');
persons.fromJsonString('[{"firstname": "Uma","lastname": "Thurman"}]');
persons.fromJsonString('[{"firstname": "Tom","lastname": "Cruise"}]');
persons.fromJsonString('[{"firstname": "Michael J.","lastname": "Fox"}]');

printLine(persons.buildString(","));

The other new function for arrays is sort(), which will obviously sort the contents of the array. Only one-dimensional arrays are supported, and only arrays of basic types or structs. For basic types, this works as you would expect:

Integer[] arr;
for (Integer i = 0; i < 10; i++) 
  arr.pushBack(rand(0, 100));
printLine(arr.buildString(","));
arr.sort();
printLine(arr.buildString(","));

In order to be able to sort an array of structs, the struct must implement a method with the following signature: Bool compare(SameStruct s). This will allow you to sort arrays of structs using whatever comparison you'd like:

struct Person {
  String firstname;
  String lastname;
  
  String toString() {
    return this.firstname + " " + this.lastname;
  }
  
  Bool compare(Person p) {
    return this.toString() < p.toString();
  }
};

Person[] persons;
persons.fromJsonString('[{"firstname": "Mark","lastname": "Wahlberg"}]');
persons.fromJsonString('[{"firstname": "Uma","lastname": "Thurman"}]');
persons.fromJsonString('[{"firstname": "Tom","lastname": "Cruise"}]');
persons.fromJsonString('[{"firstname": "Michael J.","lastname": "Fox"}]');

printLine(persons.buildString(","));
persons.sort();
printLine(persons.buildString(","));

 

Developer UI improvements


This release contains lots of small and medium improvements to the developer experience in Service. Here are some of the highlights:


Debugger/Tracing view


When debugging in real time, or when viewing a saved script trace, we have now added a dropdown to the UI with all the source locations for the current debug/trace session. For large scripts that are using #includes, this allows you to quickly switch between the different sources. In debug mode, you can use this to e.g. set a breakpoint in another file. In tracing mode, clicking in the gutter (where the red breakpoints are shown) will now instead fast-forward the trace to that location. This can be very useful when viewing large script traces: instead of having to use the slider to try to find the frame where some particular code is executed, you can rather click next to the code and the slider will move to the correct position.


Another small but welcome improvement to this view is that the width of the sidebar (containing info, variables, etc) now will be remembered in your browser and reused on subsequent views. We have also cleaned up the variable view a bit, and added a "copy value to clipboard" icon for each variable.


Working with CRMScripts, Custom screens and Extra tables


We have also done some changes to the UI when working with CRMScripts. First of all, the search functionality for scripts will now show the chosen result using the correct "View script" screen instead of a dump of the table contents. Also, when viewing a script, the "Run script" link now properly uses the includeId of the script if it is configured. Using the includeId-link instead of the id-link is recommended to make customizations more robust when migrating between instances of SuperOffice.

When editing a CRMScript, we have now changed the output frame to use a monospaced font. This makes for instance SearchEngine.executeTextTable() look much better.

One issue that has been quite annoying for some time is the complex process for creating a trace for the scripts related to a Custom screen. This has now been simplified by adding a new tab to the "View screen" screen, listing all the scripts related to this screen. Just click a script to create a trace for it.

Finally, a small improvement in the view for listing extra tables. We have now added links for searching a table or creating a new record in a table from this view, so you don't have to navigate through Requests > Extra tables, and then find the same table you just edited.

Together with some other bug fixes, we sincerely hope our latest version of SuperOffice will be a welcome improvement to your developer experience!

A lot of good stuff there! I've especially missed buildString() and creating Json Strings from Structs with all data types, so it's nice to see to those added.

After the update I've noticed that the trace screen doesn't always load properly, the load icon is just spining.. I haven't been able to pinpoint if there's anything specific in the script that causes it, but it's maybe something to look out for..
Espen Steen 28. jun 2022
Nice, we love it :)
Frode Lillerud 9. jun 2022
Great improvements!
David Hollegien 8. jun 2022