Use Command Click Scripts to move users between Groups
This article describes what Command Click Scripts are and how to use them.
Introduction
Command Click Scripts allows you to assign or remove a user from a Group after a command is executed successfully.
Requirements
- Two Groups were created named First and Second. Read more about how to create Groups here.
- Two template commands are created for your devices. You should name the template commands ModeA and ModeB. Read more about how to create template commands here.
- A Command Group will contain both of these commands. Read more about how to create Command Groups here.
- In order to use Command Click Scripts, you need to get familiar with the usage of click scripts. Read the guide about how to use click scripts here.
Creating the command click script
1. To create a Command Click Script, go to Main Menu > Admin > Development > App Builder
2. Click on + App
3. Set a name for your new app, then click on Save
4. Now click + Click Script inside your new app
5. Set a name for your new Click Script, then select the Command kind
Set the new click script to Enabled
6. Click on the Edit button and paste the following code into the editor:
var tagAdding, tagRemoving;if(command.name == ‘ModeA’) {
tagAdding = tags.getTagByName(‘First’);
tagRemoving = tags.getTagByName(‘Second’);
}
elseif(command.name == ‘ModeB’) {
tagAdding = tags.getTagByName(‘Second’);
tagRemoving = tags.getTagByName(‘First’);
}
if(tagAdding != null) {
tags.updateUsers(tagAdding.id, [user.id], []);
}
if(tagRemoving != null) {
tags.updateUsers(tagRemoving.id, [], [user.id]);
}
Note: the command should run successfully before saving the app. Make sure you're not missing any of the requirements at the beginning of this guide.
7. In the Command Groups section of the click script, select the Command Groups associated with this script. The script will be executed after the successful completion of a command only if the command is in this Command Group.
Finally, click on Save.
Results
Running the script from the editor once with one of the two commands specified in the Exposed objects and test values section under command.name should immediately move a user to the right Group and validate the script.
Now save the script and run the other command. After the command is completed, you will see that the user has moved to the other Group.