Skip to content

This repository contains an opensource library of JavaScript for SuperOffice (CRMScripts V2).

Notifications You must be signed in to change notification settings

SuperOffice/javascript-for-superoffice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What is JavaScript for SuperOffice?

JavaScript for SuperOffice (JSFSO) enables you to write scripts with javascript, moving away from the traditional CRMScript-language as a whole. The new engine implements everything the NetServer has to offer, and the syntax looks familiar to those who has previously used the webapi.

See the JavaScript for SuperOffice: A Paradigm Shift in SuperOffice CRM Customization document to read more about the changes.

See the JavaScript for SuperOffice Online Architecture document to read more about the architecture and flow.

This repo contains basic examples to get started writing scripts, and some helpers to get the proper intellisense in vscode.

Using this git repo

  1. git clone https://github.com/SuperOffice/javascript-for-superoffice.git
  2. Open the terminal and run 'npm run setup'
  3. Check out the Examples-folder

How do i run my script?

The scripts still need to be executed inside of SuperOffice!! This means you will have to copy-paste the JS-scripts into the SuperOffice-editor after creation.

VSCODE: To help the editor understand the @types we need to have the import-statement at the top of the file. This line is redundant in the SuperOffice-script, as it's imported by default.

It is also important that you import the extensionMethods as RTL, as that is what the SuperOffice-environment expects.

Lets use CreateContactEntity.js as an example:

import * as RTL from '@superoffice/webapi';
import { context } from '../../../Helpers/logHelper';
    
//Variables
const name = "NewName";

const agent = new RTL.ContactAgent();
let entity = await agent.createDefaultContactEntityAsync();
entity.name = name;
entity = await agent.saveContactEntityAsync(entity);
context.result.body = JSON.stringify(entity);

And this is what you copy-paste into your SuperOffice-Script (without the lines with import):

    
//Variables
const name = "NewName";

const agent = new RTL.ContactAgent();
let entity = await agent.createDefaultContactEntityAsync();
entity.name = name;
entity = await agent.saveContactEntityAsync(entity);
context.result.body = JSON.stringify(entity);

How do i log anything in SuperOffice

The good old print()/printLine() is now gone, and we need to use 'context.result.body' to print any of the values back into the debug-window. Example:

context.result.body = "foo";

What is 'context'

Context is the model that contains data (eventData, cgiVariables etc) in the new script.

You can run this to see whats inside the context.

context.result.body = JSON.stringify(context);

includes

Yes, you can still #include other files similar to how it was done in CRMScript. Please see ./Examples/Includes for an example.

Why not typescript

Javascript is a great language which has a lot of flexibility. This flexibility also comes with a cost, and some developers dread the idea of not using a strongly typed language. We at SuperOffice want to provide the best experience for all the developers out there, and how you choose to write your javascript is totally up to you! This means you can write typescript and compile that into javascript, or you can write javascript directly.

As of 22.05.2024 we are investigating the possibility of writing TypeScript.

Do i need to clone this repo to create scripts

No, this repo only contains a starting-point for you to make your own scripts. We supply an NPM package you can import into any project of your choosing:

URL: https://www.npmjs.com/package/@superoffice/webapi

Command: npm i @superoffice/webapi

As long as you import this package as RTL you should not have any problems.

PS: This NPM package does not contain the class Context, so you can either copy-paste the logHelper.js into your own project or create the class yourself.

Workflow

How you want to work with Javascript for SuperOffice is up to you, but as per 01.11.2023 there is no proper intellisense inside the SuperOffice (Codemirror) editor, which means that you should make use of the npm-package @superoffice/webapi to get the types.

Example workflow:

  1. Open a new folder/project in vscode
  2. Add npm-package with command 'npm i @superoffice/webapi'
  3. Create new file, with file-extension .js
  4. Add import-statement at the top of the file: 'import * as RTL from '@superoffice/webapi';'
  5. Write your script
  6. Copy your script and paste it into SuperOffice, without the import-statement in point 4.
  7. Execute script in SuperOffice and see the result

We are currently discussing the possibility to have a vscode extension that connects to a tenant and have the methods to download/upload scripts. This will simplify the workflow for developers wanting to work in vscode, but we have (for now) only a POC for this.

We also have a new endpoint in our API which allows you to pass inn a script without having it stored inside of SuperOffice: https://docs.superoffice.com/en/api/reference/restful/agent/CRMScript_Agent/v1CRMScriptAgent_ExecuteScriptByString.html It is still undecided if this endpoint will remain open when JSFSO is in production, but for testing-purposes it might come in handy.

Disclaimer

  1. This repo only contains examples on how to handle different entities, and will expand as new functionality is created.
  2. Importing your own NPM-packages are as of 22.05.2024 not supported.
  3. Only methods available in the NetServer/webapi is supported, so trying to use classes from Service (Ticket, Customer, etc) are not available. We do on the other hand know about a handful of special classes that needs to be implemented (Parser for instance).

Hopefully this shows how would to get writing new Scripts. Got any feedback? Please create an issue on this repo to improve its readability and usefulness!

About

This repository contains an opensource library of JavaScript for SuperOffice (CRMScripts V2).

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published