Friday, September 14, 2018

SuiteSignOn > How to resolve the currently logged in user to an entity type?

A NetSuite user would like to resolve the currently logged in user to an entity type. When a connection point initiates, it will do the handshake process to the external application. After the handshake process and verification is successful, the user identity information is sent on XML format. However, on the XML document, the only information given is the internal id of the currently logged in user.
The external application would like to load the entity record of the currently logged in user. A get or search is preferred. However, EntitySearchBasic is not usable (it gives out an error). CustomerRecordSearchBasic cannot be used on an employee record either. When using the get operation, a record type should be specified.

Here is how to resolve this issue:
1. The user needs to pass the entity type of the currently logged in user as an integration variable. Sample script below:
function SSOPortlet(portlet, column) {
 portlet.setTitle('Sample SSO Portlet');
 var url = nlapiOutboundSSO('customsso_sample');
 var user = nlapiGetUser();
 var entityType = nlapiLookupField('entity', user, 'type');
 url = url + '&entitytype=' + entityType;
 nlapiLogExecution('DEBUG', 'URL is: ', url);
 var htmlContent = '<iframe src="' + url + '" align="center" style="width:100%; height:150; margin:0; border:0; padding:0"></iframe>';

2. The external application should get the value of the entitytype parameter passed. In a Java servlet, here is how:
String entityType = request.getParameter("entitytype");

3. The external application can then use that parameter to resolve the user to a type. Here is a sample function for that:

private RecordRef resolveRecord(String internalId, String type) {
  RecordRef recRef = new RecordRef();
  if(type.equalsIgnoreCase("employee")) {
  else if(type.equalsIgnoreCase("customer")) {
  else if(type.equalsIgnoreCase("contact")) {
  else if(type.equalsIgnoreCase("vendor")) {
  else if(type.equalsIgnoreCase("partner")) {
  return recRef;

This is a reusable function which they can use in order to automatically resolve the current user's entity type. This is needed for SSO applications with multiple users (customer, employee, vendor, partner etc.). The RecordRef object returned by this function can then be used on a get WS operation.

No comments:

Post a Comment