How to create a group using scripts

Hi,

I want to create a group using script add members to it. I am using this script to create a group but unable to create.

var groupService = dundas.context.getService(“GroupService”);
var view = dundas.context.getService(“ViewService”)
var group = new dundas.account.Group()

group.groupKind = dundas.account.GroupKind.STANDARD
group.id = dundas.Utility.createGuid();
group.name = “Test2”
group.displayName = “Test2”
account.isEnabled = true;

var createGrp =
groupService.createGroup(group);
viewService.showLoadingRestCall(createGrp);

createGrp.done(
function(account)
{
viewshowAlert(‘Group Created’, dundas.view.NotifyType.SUCCESS, “Information”);
}
);

Can anyone tell me what Kind mistake I am committing in this script?

Hi Anupan,

I tested this script and found a couple of minor issues with this solving which got the script working for me. You have used all the right methods and services, however, on line 8 of your script you are using a property of variable “account” that you have not created so please change the “account.isEnabled = true;” to “group.isEnabled = true;” and on line 11 change the “viewService.showLoadingRestCall(createGrp);” to “view.showLoadingRestCall(createGrp);” since your view service definition is assigned to a variable called “view”.
Besides, this you will also have to make change to line 15 where you have used “viewshowAlert(‘Group Created’, dundas.view.NotifyType.SUCCESS, “Information”);” to “view.showAlert(‘Group Created’, dundas.view.NotifyType.SUCCESS, “Information”);”.
Besides, you will need to make sure that this script is run in the context of the user who is a part of “System Administrator” built-in group else you will get an error.
In such case, where you are debugging a script you can make use of the “browser development console” and can also handle the “fail” condition in your code to display the exact error using something like -
createGrp.fail(function(data){
//data.responseText - will contain the fail message
debugger;
})

I hope this helps.

1 Like