Tuesday, January 8, 2019

Retrieve the Roles internal ID of the Contact under Customer Record

This solution demostrates how to get the Roles internal ID of a Contact under a Customer record.

When loading the customer record in debugger with :
nlapiLoadRecord('customer', 149)

You can see the Contacts under the 'contactroles' subtab, but the Roles are the all the same which shows as '14'.

To see the actual Roles of the Contact in debugger, follow these steps:

1. Create a Customer Saved Search in the UI
Criteria
- Internal ID

Results:
- Name
- Contact: Internal ID
- Contact: Role
- Contact: Name

2. Reference the internal ID of the Customer Saved Search on nlapiSearchRecord
var searchresults = nlapiSearchRecord( 'customer', 116, null, null);

3. Check the Local Variables tab on debugger and expand the columns array or the search result. You will now see the actual internal ID of the Roles of the Contact record.

The following code demonstrates a Suitelet solution to the original problem. If the person is a company type, then the contact list is populated.

** START CODE ***
function suiteletList(request, response)
{
var custId = request.getParameter('id');
var isperson = nlapiLookupField('customer', custId, 'isperson');
var list = nlapiCreateList('Suitelet List');
if(isperson == 'F')
{
var f = new Array();
f.push(new nlobjSearchFilter('internalid', null, 'anyof', custId));

var c = new Array();
c.push(new nlobjSearchColumn('companyname'));
c.push(new nlobjSearchColumn('contactrole', 'contact'));

var r = nlapiSearchRecord('customer', null, f, c);

if(r!=null)
{
var columns = r[0].getAllColumns();

for(var i=0; i<columns.length; i++)
{
var colName = columns[i].getName();
if(columns[i].getJoin() != null && columns[i].getJoin() != '')
{
colName += '_' + columns[i].getJoin();
}
list.addColumn(colName, 'text', columns[i].getLabel());
}

list.addRows(r);
}
}
response.writePage(list);
}
*** END CODE ***

 

 

No comments:

Post a Comment