Fusion Manage Forum
Welcome to Autodesk’s Fusion Manage (formerly Fusion 360 Manage) Forum. Share your knowledge, ask questions, and explore popular Fusion Manage topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

User email address in scripting

11 REPLIES 11
Reply
Message 1 of 12
dkeeley
775 Views, 11 Replies

User email address in scripting

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();
}
11 REPLIES 11
Message 2 of 12
michelle.stone
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
Technical Marketing, PDM & PLM
Autodesk, Inc.
Message 3 of 12
dkeeley
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.

Message 4 of 12
michelle.stone
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
Technical Marketing, PDM & PLM
Autodesk, Inc.
Message 5 of 12
dkeeley
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.

 

Message 6 of 12
dkeeley
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();
    }

 

Message 7 of 12
michelle.stone
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
Technical Marketing, PDM & PLM
Autodesk, Inc.
Message 8 of 12
dkeeley
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.

Message 9 of 12
michelle.stone
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
Technical Marketing, PDM & PLM
Autodesk, Inc.
Message 10 of 12
dkeeley
in reply to: dkeeley

Thanks for your help Michelle.

Message 11 of 12
jdow
in reply to: michelle.stone

Was this ever resolved?

 

I have this exact need, to get the user_id from the username thats in a single selection pick list.

 

Thanks

John

JD
Message 12 of 12
john.denner
in reply to: jdow

I know this thread is pretty ancient now but I stumbled across in my search for other answers so I thought I would share my library script that returns the user object using the format of Last, First.

 

It's similar to Security.loadUser(userID) but it's really nothing fancy. You pass the function the users name as it is displayed in picklists and such, and it will lookup the user based on their first and last name. it has zero error handling but it kind of doesn't need it. Hope it helps someone.

 

The only condition of use is that you try to use it from a common library script and not by copying and pasting it in a dozen different action, condition, and validation scripts. 😉

 

 

/**
 * Returns the first user object found from the name format of Last, First
 * @param {string} userName 'last, first'
 * @returns {{}} theUser The same object returned as Security.loadUser(userID)
 * @example
 * var userInfo = getUserObjectFromName('Cop, Stop');
 * println(userInfo.id); // lee7
 * println(userInfo.email); // talktothehand@autodesk.com
* Security.listGroups(userInfo.id); // ["Village People","NKOTB"] */ function getUserObjectFromName(userName) { var theUser = Security.searchUsers({ lastName: userName.split(',')[0], firstName: userName.split(',')[1].trim() }); return theUser[0]; }

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report