Use url.resolveRecord to get the url of the created Invoices.
Use url.resolveDomain to get the domain of the url.
Use transformUrl function to transform the url into the desired format.
let invoiceUrl = url.resolveRecord({
recordType: 'record.Type.INVOICE',
recordId: invoiceRecId,
isEditMode: false
});
let domain = url.resolveDomain({
hostType: url.HostType.APPLICATION
});
let transformedURL = transformURL(invoiceUrl, domain);
function transformURL(originalURL, domain) {
try {
log.debug("originalURL", originalURL);
// Extract the query parameters
let urlParts = originalURL.split('?');
let queryParams = urlParts[1].split('&');
// Construct the new URL using the resolved domain
let newURL = 'https://' + domain + urlParts[0] + '?' + queryParams.join('&') + '&whence=';
log.debug("newURL", newURL);
return newURL;
} catch (error) {
log.error('Error transforming URL:', error);
return null;
}
}