简体   繁体   中英

How to get profile image of logged user in suitescript 2.0 in Netsuite?

I am able to get logged user details through below suitescript 2.0

    runtime.getCurrentUser();

The response is

{
    "id": 12345,
    "name": "ABC",
    "email": "abc@gmail.com",
    "location": 0,
    "department": 0,
    "role": 3,
    "roleId": "administrator",
    "roleCenter": "BASIC",
    "subsidiary": 1,
    "timezone": "Asia/Calcutta"
} 

There is no property to get image from response of getCurrentUser() . Any other way to get profile picture of logged user in Suitescript 2.0?

You would need to get the image id from the employee (user) record using the record or search module, passing in the user id:

var userId = runtime.getCurrentUser().id;
var userRecord = record.load({  //make sure 'N/record' is defined as record
    type: record.Type.EMPLOYEE,
    id: userId
});
var imageId = userRecord.getValue('image');

Or:

var userId = runtime.getCurrentUser().id;
var imageId = search.lookupFields({
    type: search.Type.EMPLOYEE,
    id: userId,
    columns: 'image'
}).image[0].value;

For server scripts, you can then use the N/file module to load the image file, passing in the imageId . If you need to get the image in the client side, you can get the text of the field instead of the value:

var userId = runtime.getCurrentUser().id;
var imageId = search.lookupFields({
    type: search.Type.EMPLOYEE,
    id: userId,
    columns: 'image'
}).image[0].text;

which will return the relative path to the image in the file cabinet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM