User Class (How do we instantiate a user class in Studio?)

How would I instantiate using the following user class in a WebForm?

User Class

I created a user class named ucJeremyClass in Studio under the Explorer’s Classes theme.

constructor
	this.log = []
	
function clearLog()
	this.log = []
	
function addEntry(note : string)
	this.log.push(string(note))
	
function getLog()->json : string
	json = jsonStringify(this.log, *)
	
function countLog()->count : integer
	count = this.log.length

WebForm Data Source

In a WebForm, I also created a data source named myLog to hold a reference to an instance of ucJeremyClass.

QUESTIONS

  1. How do I instantiate my user class ucJeremyClass to assign a reference to the data source named myLog?

  2. Where can user classes be used in Qodly?

Hey Jeremy.

Only exposed Function through DataStore (ds), DataClass, Entity or Selection can be used directly in Qodly studio. In your case:

User classes can be used in DataStore, DataClass, Entity, Selection’s functions or the other user classes’s functions.

  1. How do I instantiate my user class ucJeremyClass to assign a reference to the data source named myLog?

Do you need this class to handle all your logs or it will be logs by webForms ?

@ayoub

I would like to know how to assign the log instance both globally and for just a single WebForm.

For the moment, I am trying to keep the log simple. So, I would like to assign it to a WebForm.

@jeremy

here’s a use case, in the dataStore you can create two exposed functions

exposed function getLogs() : string
	var logcs : cs.log
	logcs=cs.log.new()
	if (session.storage.logs == null)
		use (session.storage)
			session.storage.logs=objectCopy(logcs, kShared)
		end 
	end
	return session.storage.logs.getLog()
exposed function addLogs(note: string)
	if (session.storage.logs != null)
		session.storage.logs.addEntry(note)
	end

i created a simple webForm

logs is a text component to display the logs
log is a text input and add is a button
first you should create 2 data sources (both of them are strings)
bind logs to the text component to display logs and bind log to the text input

image

on webForm’s onLoad add this event

and add those event to onClick on add button

you should get something like this

and when you click on add

PS: you will see i saved the class’ object in the session’s storage so if the session is kept alive you can get the logs.