Item Object: Master Property

Master is one property of Item object. It contains the item’s DMS ID, workspace ID, owner, additional user owners and additional group owners. In this post, we will go through each of them.


Item’s DMS ID

item.master.dmsID returns the item’s DMS ID which is read-only Number type.


Item’s workspace ID

item.master.workspaceID returns the ID of the workspace which the item belongs to, which is read-only Number type.


Item’s owner

item.master.owner returns an User object contains the information about that owner user, e.g. name, phone, email, license, etc. That’s all you need to know about User object at this moment. We will have a separate post to focus on it.

The owner property is editable, so we can update the item’s owner using script.

var newOwner = Security.loadUser(‘newOwnerUserId’); // load user with id
item.master.owner = newOwner;  // update owner

Here we use Security.loadUser(‘newOwnerUserId’) to get a new owner user. The function takes an user ID; returns the User object representing the user. The Security object can be used to handle users, groups and roles. We will be explained in detail in the future post. In this post, we only need to know how you to use its loadUser function and loadGroup function.

We are also able to clone the owner from another item like this:

item.master.owner = loadItem(1234).master.owner;


Item’s additional user owners

item.master.additionalOwners gives us an Array of User objects. To add additional user owners, we need to push each user object into this array.

var newAdditionalUserOwner = Security.loadUser(‘UserId’);
item.master.additionalOwners.push(newAdditionalUserOwner);

To remove all the additional user owners, we can do this:

item.master.additionalOwners.length = 0;

To find and remove particular additional user owner, we can use splice,

var ownerToRemove = Security.loadUser(‘UserId’);
var index = item.master.additionalOwners.indexOf(ownerToRemove);
if (index > -1) { // if the owner exists in the array
    item.master.additionalOwners.splice(index, 1);
}

If we want to send email notification to all the additional user owners, we could use the code like this:

var additionalOwners = item.master.additionalOwners;
for (var index in additionalOwners) {
    var email = new Email();
    email.to = additionalOwners[index].email;
    email.subject = "Owner Notification";
    email.body = "Please update current workflow.";
    email.send();
}


Item’s additional group owners

item.master.groupAdditionalOwners returns an Array of Group objects. We could use the same procedure as what we did for the User object above to do the add/remove/clear actions on the group array. The only difference is that we are working on Group object instead of User. To get a Group object we need use Security.loadGroup('Group Name'). This function takes the String of group name as input; returns a Group object.


Tips

When we are writing script code, we often need to know the user ID for certain user. (The function Security.loadUser(‘UserId’) introduced above is an example.) But to find a user’s ID is a tricky thing, so here is an easy way to get it quickly. You need go to “Users” page first [Administration –> Security –> Users]. Then after clicking the user’s name under the “User Name” column, you will find the user’s ID is hidden in the address of the new window.

Capture

This user’s ID is “A1mMw”. Now you can use Security.loadUser(‘A1mMw’) to load the User object for this user in scripting.

To use the function Security.loadGroup('Group Name'), we need to know the group name. Finding group name in PLM is very straightforward. In the Groups page [Administration –> Security –> Groups], each of the displayed names under column “Name” is just the input variable you need for that function.

 

–Michal


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading