Wednesday, February 20, 2019

Ability to mimic the View/Edit link via SuiteScript

Customer have a custom record that contains sublist created via script. He would like to make one of the field
in the sublist as link that when clicked it will redirect to another record.

Unable to set the field created by addField method as link because inlinehtml is not available as field type.

In order to redirect to another record the possible solution would be emulating the View/Edit links via SuiteScript

Below is the sample code that will create a tab and a sublist that will contain customer record. Using
"url" field type on the addField method to create a link to the custom record and setLinkText to sets the text to be display
on the URL field.

This will be deployed on Before Load User Event Script in a Custom Record

function tabsToCustomRecord(type, form)
{
var sampleTab = form.addTab('custpage_sample_tab', 'Sample Tab');
var contacts = form.addSubList('custpage_contacts', 'editor', 'Custom Contacts','custpage_sample_tab');

contacts.addField('view', 'url', 'View', null).setLinkText('View');
contacts.addField('edit', 'url', 'Edit', null).setLinkText('Edit');
var entity = contacts.addField('custpage_entityid', 'text', 'Name');
var email = contacts.addField('custpage_email', 'email', 'Email');

var columns = new Array();
columns[0] = new nlobjSearchColumn('companyname');
columns[1] = new nlobjSearchColumn('email');
columns[2] = new nlobjSearchColumn('internalid');

// reference a Customer saved search
var searchresults = nlapiSearchRecord('customer',643, null, columns);
nlapiLogExecution('DEBUG','DEBUG',searchresults );
var netsuiteSiteUrl = 'https://system.na1.netsuite.com';
for ( var i = 1; searchresults != null && i < searchresults.length; i++ )
{

var viewUrl = netsuiteSiteUrl + nlapiResolveURL ('RECORD', 'customer', searchresults[i].getId(), 'VIEW');
var editUrl = netsuiteSiteUrl + nlapiResolveURL ('RECORD', 'customer', searchresults[i].getId(), 'EDIT');
   
contacts.setLineItemValue('custpage_entityid',i,searchresults[i].getValue(columns[0]))
contacts.setLineItemValue('custpage_email',i,searchresults[i].getValue(columns[1]))
contacts.setLineItemValue('view', i, viewUrl);
contacts.setLineItemValue('edit', i, editUrl);
}


}

DISCLAIMER: The sample code described herein is provided on an "as is" basis, without warranty of any kind, to the fullest extent permitted by law. Netsuite Inc. does not warrant or guarantee the individual success developers may have in implementing the sample code on their development platforms or in using their own Web server configurations.

Netsuite Inc. does not warrant, guarantee or make any representations regarding the use, results of use, accuracy, timeliness or completeness of any data or information relating to the sample code. Netsuite Inc. disclaims all warranties, express or implied, and in particular, disclaims all warranties of merchantability, fitness for a particular purpose, and warranties related to the code, or any service or software related thereto.

Netsuite Inc. shall not be liable for any direct, indirect or consequential damages or costs of any type arising out of any action taken by you or others related to the sample code.

No comments:

Post a Comment