Click Scripts: User Right-click Menu

Click scripts can be executed from the User right-click menu. You can combine multiple actions commonly used together into one, e.g. adding a user to a tag while removing it from other tags.

Enabling and creating Click Scripts

Details on enabling and creating click scripts can be found here.

Create a new click script by choosing Main Menu > Admin > Development > App Builder > Add new Click Script (in the Click Scripts section).

To create click scripts shown in the user right-click menu, select the UserRightClickMenu type in the Edit Click Script form. In this case, the Enabled option determines whether the script will be listed in the right-click menu for eligible users.

Apart from this, you can control which roles get to use which scripts by restricting the access to scripts listed under the _UseClickScript privilege for that role. To be able to immediately see the changes to the interface after you create a script, make sure that this privilege is enabled for the role with the edit privilege.

Example: moving a user between tags

Create three tags named, for example, FirstSecond, and Third. Let us suppose that only one of these tags should be assigned to a user at a time. When the operator wants to move a user from one tag to another, they would need to open the user or the tags, uncheck the old and check the new tag/user, and save the changes.

Instead, we can create a UserRightClickMenu click script with the following script:

 
var tag1 = tags.getTagByName('First'); // get 'First' tag by name
var tag2 = tags.getTagByName('Second'); // get 'Second' tag by name
var tag3 = tags.getTagByName('Third'); // get 'Third' tag by name
 
// add current user to First, remove nothing from the First
// add nothing to the Second, remove current user from Second
// add nothing to the Third, remove current user from Third
tags.updateUsers(tag1.id, [user.id], [])
tags.updateUsers(tag2.id, [], [user.id])
tags.updateUsers(tag3.id, [], [user.id])

Enable and save the script, naming it Move to First as shown below.

And, when you click on a user on the map or in the asset list, you will see that a new option is available as shown below.

Open the created click script again. With the Create Copy button, you can quickly create a copy of it, and quickly create analogous scripts for moving the user to the second and the third tag.

Name the second script Move to Second, change the last three lines to the following, then save:

 
tags.updateUsers(tag2.id, [user.id], [])
tags.updateUsers(tag1.id, [], [user.id])
tags.updateUsers(tag3.id, [], [user.id])

Name the third script Move to Third, change the last three lines to the following, then save:

 
tags.updateUsers(tag3.id, [user.id], [])
tags.updateUsers(tag1.id, [], [user.id])
tags.updateUsers(tag2.id, [], [user.id])

After saving the other two scripts, the user right-click menu should have all three available options. Clicking on any of them will execute the script, adding the user to the appropriate tag while removing it from the other two. Reopen a user or tag edit window to see the changes.

Notes

  • As with geofence click scripts, you can also generate HTTP requests with these scripts. Read more on the geofence click scripts for instructions on enabling logging from a script to a log file.
  • Note that clicking Run Script while editing click scripts actually runs the script for the selected user, executing any of the specified actions (e.g. adding/removing tags as in the example above).
  • When editing the script, click on the items in the object tree of the script editor to see more detailed information on other parameters and methods available for this type of script.