FORUM CTRLX AUTOMATION
ctrlX World Partner Apps for ctrlX AUTOMATION
Dear Community User! We have started the migration process.
This community is now in READ ONLY mode.
Read more: Important
information on the platform change.
11-02-2023 07:52 PM
Is there a way to add a new user to the WebIQ user management system with a local script?
Solved! Go to Solution.
11-02-2023 09:05 PM - edited 11-02-2023 09:07 PM
Hey Brian,
Example code is below. I stole the createUser function from the default user management widget handler included in the controls library. I didn't see a clear way to do this using the methods included in the User and UserManagement classes. Visuals User Management
(function () {
/**
* replace module name with a custom name for the local-script.
*
* All local-script should be attached to the "custom.ls" package.
* If more than one script is required for an application, a common root package
* should be created (e.g. "custom.ls.customerName.*").
*/
var MODULE_NAME = "create_user",
ENABLE_LOGGING = false,
RECORD_LOG = false,
logger = shmi.requires("visuals.tools.logging").createLogger(MODULE_NAME, ENABLE_LOGGING, RECORD_LOG),
fLog = logger.fLog,
log = logger.log,
module = shmi.pkg( MODULE_NAME );
// MODULE CODE - START
/* private variables */
/* private functions */
function createUser(username, password, additionalProperties) {
const { ConnectSession } = shmi.visuals.session,
{ User } = shmi.requires("shmi.visuals.controls.iq-user-management"),
newProperties = User.translateInternal2Api(additionalProperties || {});
newProperties.username = username;
newProperties.password = password;
return ConnectSession.requestPromise("user.add", newProperties).then(() => new User(username, newProperties));
}
/**
* Implements local-script run function.
*
* This function will be called each time a local-script will be enabled.
*
* @param {LocalScript} self instance reference of local-script control
*/
module.run = function (self) {
//Place your Code here
createUser("test_user", "test_pw");
/* called when this local-script is disabled */
self.onDisable = function () {
self.run = false; /* from original .onDisable function of LocalScript control */
};
};
// MODULE CODE - END
fLog("module loaded");
})();
11-03-2023 09:54 AM
Please note that when using undocumented functions the functionality might break in future versions of WebIQ without any prior notice or support.
I will however take up the question as a suggestion for adding such functionality to the UserManager class.
11-06-2023 09:37 PM
Thanks Sam, works great!