Script include query

Samantha Sam
Tera Contributor

Hi,

There is an OOB UI action condition as below:

current.canWrite() && (current.state!=ProblemTaskState.States.ASSESS)

where ProblemTaskState is a script include.

How can a script include be called without instantiating (no new keyword is used).

1 ACCEPTED SOLUTION

Giles Lewis
Giga Guru

When you write a Script Include to create a Javascript class, it can have instance properties and static properties.

Normally you declare instance properties for methods (functions) and variables. You do this by declaring them inside the prototype definition. Methods declared in this fashion can use the "this" keyword to reference instance variables. In other words, the different methods within the Script Include can share data with each other.

However, you can also declare static functions and variables.

Notice the syntax used to declare ProblemTaskState.States

ProblemTaskState.States = { 
    NEW: ProblemTaskStateSNC.NEW, 
    ASSESS: ProblemTaskStateSNC.ASSESS, 
    WORK_IN_PROGRESS: ProblemTaskStateSNC.WORK_IN_PROGRESS, 
    CLOSED: ProblemTaskStateSNC.CLOSED 
}; 

Notice how it has been declared outside of the prototype definition. When functions and variables are declared in this manner, you can reference them without using the new keyword. The disadvantage is that functions declared in this manner do not have access to this. Static functions cannot share data with other functions in the Script Include.

View solution in original post

3 REPLIES 3

cmcclendon
Mega Guru

At the very least, a call to a script include would contain parenthesis, like :

new ProblemTaskState().function().

This is simply comparing the value of the current (form) state field value to the ProblemTask.state value of 'ASSESS'.

This looks like a condition to execute a script.

Does this help?

-Chris

Giles Lewis
Giga Guru

When you write a Script Include to create a Javascript class, it can have instance properties and static properties.

Normally you declare instance properties for methods (functions) and variables. You do this by declaring them inside the prototype definition. Methods declared in this fashion can use the "this" keyword to reference instance variables. In other words, the different methods within the Script Include can share data with each other.

However, you can also declare static functions and variables.

Notice the syntax used to declare ProblemTaskState.States

ProblemTaskState.States = { 
    NEW: ProblemTaskStateSNC.NEW, 
    ASSESS: ProblemTaskStateSNC.ASSESS, 
    WORK_IN_PROGRESS: ProblemTaskStateSNC.WORK_IN_PROGRESS, 
    CLOSED: ProblemTaskStateSNC.CLOSED 
}; 

Notice how it has been declared outside of the prototype definition. When functions and variables are declared in this manner, you can reference them without using the new keyword. The disadvantage is that functions declared in this manner do not have access to this. Static functions cannot share data with other functions in the Script Include.

Hi Giles, thank you for the detailed explanation.