The below function is used to check whether the URL is internal or external.
the check is done using the scriptContext.request as parameter to the below function.
/**
* to check whether the URL is external or internal
* @param {} request
* @returns {boolean}
*/
function checkIfExternal(request ) {
try {
let host = request.headers[‘host’];
return host.includes(‘.extforms.netsuite.com’);
} catch (e) {
log.error(‘error @ checkIfExternal’, e);
return false;
}
}
let isExternal =checkIfExternal(request );
the function will return true if the URL is External.
The below function will redirect the suitelet to the given suitelet with the parameter as isExternal, which is generated in the checkIfExternal function.
by providing the scriptId, deploymentId to redirect with dynamically assigning the isExternal variable in suitelet script
/**
* Function to get Resolved URL
* @param {*} scriptId
* @param {*} deploymentId
* @param {*} isExternal
* @returns
*/
getResolvedUrl(scriptId, deploymentId, isExternal, param) {
try {
return url.resolveScript({
scriptId: scriptId,
deploymentId: deploymentId,
returnExternalUrl: isExternal,
params: param
});
} catch (e) {
log.error(‘Error @ getResolvedUrl’, e);
return ”;
}
},