Duplicating standard role through code in Axapta 2012

Hi all,

Kindly help how can I duplicate existing roles in AX 2012? let say we have Account manager and I want to create a duplicate of it through code.How it can be done. Kindly help me .

Regards,

Kalpna

static void duplicateRole(Args _args)

{

#AOT

#Properties

TreeNode treeNode = TreeNode::findNode(#SecRolesPath + #AOTDelimiter + “SystemUser”);

TreeNode treeNodeNew;

securityRoleName roleName = ‘NewSystemUser’;

treeNodeNew = treeNode.AOTDuplicate();

treeNodeNew.AOTsetProperty(#PropertyName, roleName);

treeNodeNew.AOTsave();

}

Thanks Kranthi sir.Its working fine and as expected.