Skip to main content

Developer Mode Survey Access

Description

Users can see surveys on channel workspaces according to different settings that act as filters determining the survey's accessibility. Among these settings, the Developer Mode permits the use of custom code to program the survey's availability.

note

Go to the survey settings panel for more details on Access configurations.

Setup

To use custom code to program survey accessibility:

survey access
  1. Select the Administrator on the Main Menu Bar.
  2. From the Administrative Panel, choose Surveys.
  3. In the Form table, choose to edit the survey you wish to customize to open the survey's settings panel.

survey access
  1. Toggle on the Developer Mode option.
  2. Choose the appropiate context.
  3. Place the code script in the function field.
note

Configuration details and code guidelines are explained below. Code examples and expected results are shown further below.

tip

See the Embedded Code Editor section for more information on how to use the editor.

Coding Guide

The code script used to program the survey's accessibility should follow the guidelines specified below.

Context

The context field indicates a relevant source from which data can be extracted. Sources are Cotalker objects structured with a corresponding data model. The context can be used as a variable representing the object within the code to extract data from an indicated source.

note
  • Currently, only the channel#task context is available. This context permits retrieving data from the task channel associated with the survey.
  • The channel#task context can be used as a variable that allows your code to access the task's data.
  • The task's data is structured according to the COTTask data model.

Function

Consider the following guidelines for the code to be used:

  • The code must be a function written in Javascript. The function must be named run without any arguments.
  • The function must return a Hidden command array.
  • The code must include the context as a variable in your code if you wish to retrieve data from the available contexts.

Structure Example

function run() {
/* yourCode; */
return [{
cmd: 'HIDDEN',
value: true | false
}];
}

Example

Below we share an example of code used to determine accessibility and how it affects end-users.

The function follows the following logic:

  1. First, the channel#task context is declared as the task variable.
  2. Then it checks to see if the channel corresponds to a task channel. If no task is found, the Hidden command must still be returned. It is returned with a false value.
  3. If a task is present, then the cost field's value is examined. If the value is equal to or less than 5000, then the survey is made unaccessible by returning a Hidden command with a true value. Otherwise, a false value is returned, making the survey accessible to users in the channel.
Extracting Context Data
  • In this example, we use the task variable – which represents the context source – to retrieve data from the task's additional fields.
  • Additional field types vary. In this case, we gather data from the additional fields stored in a task's extensions field. See the COTTask data model for details.

Code Sample

function run() {
const task = context['channel#task'];
console.log('Checking survey visibility.', task);
if (!task) {
console.log('No task is present.');
return [{
cmd: 'HIDDEN',
value: false
}, ]
}
if (task.extensions.c_purchaseorder_active.cost_task_po <= 5000) {
console.log('Survey is not accessible.');
return [{
cmd: 'HIDDEN',
value: true
}, ]
}
}

Expected Results

Below is an example of a survey following the logic expressed in the code used above.

The task's cost field is set to 2000, meaning that the survey cannot be accessed through the actions button at bottom of the channel workspace:

editable survey

The task's cost field has been manually changed to 6000, making the survey accessible to users through the actions button found at the bottom of the channel workspace:

editable survey

Related Resources