0

I need to set a User Expando field value in a Javascript Function in liferay. It is possible to do?

1 Answers1

1

You can use the json api like this way

Liferay.Service(
  '/expandovalue/add-value',
  {
    companyId: 20154,
    className: 'com.liferay.portal.model.User',
    tableName: 'CUSTOM_FIELDS',
    columnName: 'test',
    classPK: 30924,
    data: 'test'
  },
  function(obj) {
    console.log(obj);
  }
);

where

columnName is the name of your custom field

classPK is the entity id in this case userId

data the value of the custom field

Romeo Sheshi
  • 901
  • 5
  • 7
  • Thank you! This is very useful. – Enzo Terranova Apr 03 '17 at 07:33
  • I'm new with JSON API. I used `classPK : <%=selUser.getUserId() %>,` to retrieve user id, and `data : A.one('#userAdminId').get('value')` to set data. But the value is a String, and the type of expando is a long. It is possible to cast the value or i must to change the type of expando field? – Enzo Terranova Apr 03 '17 at 08:27
  • just add user.getUserId()+'' this with trasform it to string but i think is better to transform the type of exapando to long – Romeo Sheshi Apr 03 '17 at 08:34