Foros de discusión

Add boolean value when making jsonws call

Gwowen Fu, modificado hace 9 años.

Add boolean value when making jsonws call

Expert Mensajes: 315 Fecha de incorporación: 27/12/10 Mensajes recientes
Hi,
How could I add a boolean value when making the following jsonws call?

The returning data returns {exception: "com.liferay.portlet.expando.ValueDataException: Co…ompatible with type custom.field.java.lang.String"}

Liferay.Service(
	'/expandovalue/add-value', {
	  p_auth: Liferay.authToken,
	  companyId: themeDisplay.getCompanyId(),
	  className: 'com.liferay.portal.model.User',
	  tableName: 'CUSTOM_FIELDS',
	  columnName: 'address-verified',
	  classPK: themeDisplay.getUserId(),
	  data: true
	},
	function(data) {
	  console.log(data);
	}
);


Thank you!
Gwowen
thumbnail
Shinn Lok, modificado hace 9 años.

RE: Add boolean value when making jsonws call (Respuesta)

Junior Member Mensajes: 89 Fecha de incorporación: 14/01/11 Mensajes recientes
Looks like the '/expandovalue/add-value' that takes in boolean or other types besides strings aren't exposed as json services.

The workaround is probably just to use '/expandovalue/add-values'. Something like:

Liferay.Service(
  '/expandovalue/add-values',
  {
    companyId: themeDisplay.getCompanyId(),
    className: 'com.liferay.portal.model.User',
    tableName: 'CUSTOM_FIELDS',
    classPK: themeDisplay.getUserId(),
    attributeValues: {"address-verified": true}
  },
  function(obj) {
    console.log(obj);
  }
);
Gwowen Fu, modificado hace 9 años.

RE: Add boolean value when making jsonws call (Respuesta)

Expert Mensajes: 315 Fecha de incorporación: 27/12/10 Mensajes recientes
Shinn Lok:
Looks like the '/expandovalue/add-value' that takes in boolean or other types besides strings aren't exposed as json services.

The workaround is probably just to use '/expandovalue/add-values'. Something like:

Liferay.Service(
  '/expandovalue/add-values',
  {
    companyId: themeDisplay.getCompanyId(),
    className: 'com.liferay.portal.model.User',
    tableName: 'CUSTOM_FIELDS',
    classPK: themeDisplay.getUserId(),
    attributeValues: {"address-verified": true}
  },
  function(obj) {
    console.log(obj);
  }
);


Hi Shinn,

Thanks a lot. That's just what I need. I tried that before and that didn't work for me. Your response made me to take a second look.
It works for me after I add extra quotes for attributeValues.

Liferay.Service(
  '/expandovalue/add-values',
  {
    p_auth: Liferay.authToken,
    companyId: themeDisplay.getCompanyId(),
    className: 'com.liferay.portal.model.User',
    tableName: 'CUSTOM_FIELDS',
    classPK: themeDisplay.getUserId(),
    attributeValues: '{"address-verified": true}'
  },
  function(obj) {
    console.log(obj);
  }
);


Do you know which Liferay JSP page will be loaded just once after user logged in and could be overridden by a hook? I tried to redirect user to an address verification page if address-verified custom field is set to false. The WebKeys.LAST_PATH (name might be wrong) doesn't work for me so I want to use Javascript to change document.location.

Thanks again!
Gwowen