Forums de discussion

Add boolean value when making jsonws call

Gwowen Fu, modifié il y a 9 années.

Add boolean value when making jsonws call

Expert Publications: 315 Date d'inscription: 27/12/10 Publications récentes
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, modifié il y a 9 années.

RE: Add boolean value when making jsonws call (Réponse)

Junior Member Publications: 89 Date d'inscription: 14/01/11 Publications récentes
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, modifié il y a 9 années.

RE: Add boolean value when making jsonws call (Réponse)

Expert Publications: 315 Date d'inscription: 27/12/10 Publications récentes
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