PLM 360 General Discussion

Reply
Mentor
dkeeley
Posts: 214
Registered: ‎10-04-2012
Message 1 of 10 (216 Views)

User email address in scripting

216 Views, 9 Replies
12-02-2012 03:07 PM

Hi,

 

I have a script that needs to be able to access a user's email address to send an email. I'm having trouble working out the script to access this user item data.

 

So far I have something like this;

 

var user = item.TEAM[0];                       
var user_details = Security.loadUser(user);
var test = user_details.email;

 

The online help has something like this but I cant seem to work out how to use it correctly;

 

var users = Security.listUsersInGroup('Quality');

for(var index in users) {
  email.to = users[index].email;
  email.send();
}
Product Support
michelle.stone
Posts: 220
Registered: ‎02-21-2012
Message 2 of 10 (210 Views)

Re: User email address in scripting

12-02-2012 05:32 PM in reply to: dkeeley

I've done a couple blogs with email examples - see if either of these get you what you need:

E-mail for the Masses

Postal Service

 

Hope that helps!

 

Michelle

 



Michelle Stone
PLM Product Manager
Autodesk, Inc.
Mentor
dkeeley
Posts: 214
Registered: ‎10-04-2012
Message 3 of 10 (197 Views)

Re: User email address in scripting

12-03-2012 06:32 AM in reply to: dkeeley

Hi Michelle,

 

I'm still having problems. Can you tell me how to extract the email address from a user that has been selected from a picklist?

 

David.

Product Support
michelle.stone
Posts: 220
Registered: ‎02-21-2012
Message 4 of 10 (187 Views)

Re: User email address in scripting

12-03-2012 11:46 AM in reply to: dkeeley

Another example!  Here's a picklist set up to all users and the script I use to send to whomever is selected.

user_picklist.png

 

Script:

email_script.png

 

Hope that helps!

 

Michelle



Michelle Stone
PLM Product Manager
Autodesk, Inc.
Mentor
dkeeley
Posts: 214
Registered: ‎10-04-2012
Message 5 of 10 (184 Views)

Re: User email address in scripting

12-03-2012 01:34 PM in reply to: michelle.stone

Hi Michelle,

 

Thanks for the info. I think I can see what the problem is now.

 

If I'm correct the 'User, ALL' picklist contains user ids. That way you can access the email address using the Security.loaduser formula.

 

But I don't seem to have that picklist. I have a picklist called 'Users, ALL by Name' which returns the name of the user - not the id. So I don't think you can use Security.loaduser on a user's full name - you need the userid.

 

How can I go about replicating the 'User, ALL' picklist that you have shown in your screenshot?

 

David.

 

Mentor
dkeeley
Posts: 214
Registered: ‎10-04-2012
Message 6 of 10 (181 Views)

Re: User email address in scripting

12-03-2012 02:31 PM in reply to: dkeeley

Hi Michelle,

 

I have just tested my theory and I believe I am correct. You can see in the attached image that the email address is recovered correctly if I use a username (not the user's name). So to solve this issue I need to be able to do one of two things;

 

1. Create a user picklist that returns username (e.g. dkeeley) NOT the user name (e.g. David Keeley)

 

2. Find a way to get the email address from a user name.

 

In the meantime I've written the following script to do it (but its dependant on all usernames being in the same format);

 

var i = 0;
var team_size = item.TEAM.length;
var email = new Email();
email.subject = 'Comment Added to Special Project '  +item.NUMBER;
email.body = getPrintView('Project Comment Email');

while (i<team_size)
    {
    var user_name = item.TEAM[i];
    var user_name_length = user_name.length;
    var char_position = user_name.indexOf(',');
    var letter = user_name.charAt(char_position + 2);
    var user_surname = user_name.substring(0,char_position);
    var user_id_temp = letter + user_surname;
    var user_id = user_id_temp.toLowerCase();
    var user_details = Security.loadUser(user_id);
    i++;
    email.to = user_details.email;
    email.send();
    }

 

Product Support
michelle.stone
Posts: 220
Registered: ‎02-21-2012
Message 7 of 10 (178 Views)

Re: User email address in scripting

12-03-2012 02:53 PM in reply to: dkeeley

Sorry David - that was a wicked old example I posted, but looks like you got it sorted out!  Another example for extracting the user info from the picklist result (assuming you name the field PLM360_USER_NAME:

 

var user= item.PLM360_USER_NAME;
var securityInfo=Security.loadUser(user); 
item.FIRST_NAME=securityInfo.firstName;
item.LAST_NAME=securityInfo.lastName;
item.TITLE=securityInfo.title;
item.MAIL=securityInfo.email;
item.ORGANIZATION=securityInfo.organization;
 
Thanks!
Michelle


Michelle Stone
PLM Product Manager
Autodesk, Inc.
Mentor
dkeeley
Posts: 214
Registered: ‎10-04-2012
Message 8 of 10 (174 Views)

Re: User email address in scripting

12-03-2012 03:52 PM in reply to: dkeeley

Hi Michelle,

 

The problem with this as I understand it is that for me the item.PLM360_USER_NAME = 'Keeley, David' NOT 'dkeeley'. The former value is not the userid so cannot be used to load user information.

 

I need a way to get the userid 'dkeeley' from the user name 'Keeley, David' OR I need to modify the picklist to return the userid instead of the user name.

 

Any thoughts?

 

David.

Product Support
michelle.stone
Posts: 220
Registered: ‎02-21-2012
Message 9 of 10 (162 Views)

Re: User email address in scripting

12-04-2012 11:18 AM in reply to: dkeeley

David - there currently isn't a way to get the userid from a picklist, but they are working on it. 



Michelle Stone
PLM Product Manager
Autodesk, Inc.
Mentor
dkeeley
Posts: 214
Registered: ‎10-04-2012
Message 10 of 10 (152 Views)

Re: User email address in scripting

12-06-2012 09:47 AM in reply to: dkeeley

Thanks for your help Michelle.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Ask the Community