I have a suitelet that is grabbing data from a sav...
# suitescript
m
I have a suitelet that is grabbing data from a saved search. Is it possible to create url links on these value? Also, could we apply html on the columns?
message has been deleted
m
You can add formula columns to the search results to display in your list. Here's a formula field in the results that builds a URL to a Suitelet:
Copy code
columns: [
    {
        "name": "formulatext_0",
        "formula": "'<a href=\"/app/site/hosting/scriptlet.nl?script=customscript_custom&deploy=customdeploy_deploy&' || 'recordType=' || {recordtype} || '&recordId=' || {internalid} || '\">' || {tranid} || '</a>'"
    }
]
👌 1
m
Thanks, I'll try this
r
I’d recommend url.resolveRecord for creating the value of href.
m
Able to show me an example at all?
r
Copy code
const createRecordLink = (recordId, recordType) => {

            const searchToRecordMap = {
                CustInvc: record.Type.INVOICE,
                CustCred: record.Type.CREDIT_MEMO,
                VendBill: record.Type.VENDOR_BILL,
                ExpRept: record.Type.EXPENSE_REPORT,
                VendCred: record.Type.VENDOR_CREDIT
            };
            const domain = url.resolveDomain({hostType: url.HostType.APPLICATION});
            const recordPath = url.resolveRecord({
                isEditMode: false,
                recordId: recordId,
                recordType: searchToRecordMap[recordType]
            });

            return `https://${domain}${recordPath}`;
        };
👍 1
m
I used url.resolveRecord to construct a link - but 1) I need this to be an actual link 2) instead of showing the full link show on the doc id for instance. Possible?
r
Ya, you're going to build an a tag similar to what mike showed above. look up a href (html). Sorry, im on mobile
The link you built will be the value of href. Text goes between the brackets
m
@Mike Robbins - where do I put that formula? Inside the saved search or in the code itself. I tried this but it doesn't set the column on the suitelet:
Copy code
var doc_number_url = nsfResolveRecordUrl(record_type, internal_id)

var doc_number_url_link = result.getValue({
    name: "formulatext",
    formula: '<a href=' || {doc_number_url} || ' target=_blank>Link</a>'
});

sublist.setSublistValue({
    id: 'custpage_doc_number',
    line: counter,
    value: doc_number_url_link
});
m
Inside the saved search as a column, so
Copy code
search.create({
 type: '',
 filters: [],
 columns: [
  {
    "name": "formulatext_0",
    "formula": "'<a href=\"/app/site/hosting/scriptlet.nl?script=customscript_custom&deploy=customdeploy_deploy&' || 'recordType=' || {recordtype} || '&recordId=' || {internalid} || '\">' || {tranid} || '</a>'"
  }
 ]
);
After you run the search and get the results, you can put this value in a TEXT field in your sublist like this:
Copy code
sublist.setSublistValue({
 fieldId: 'your_field_id',
 value: result.getValue({ name: 'formulatext_0' }),
 line: I
});
If you need multiple formulas, you can change the
_0
in the name to
_1
for however many you need.
👌 1
r
If you already have the link string built, you just need to create an html “a” element.
Copy code
const val = `<a href=${doc_number_url_link}>Whatever Text</a>`;
sublist.setSublistValue({
    id: 'custpage_doc_number',
    line: counter,
    value: val
});
👌 1
The above is using a string literal, which is 2.1, but you can do the same thing with concatenation.
You haven’t shown enough code for us to know what you’re doing wrong. For instance, we can’t see where counter is set, if you’re in a loop, etc. Try reposting this with more code.
m
Sorry, should have said that I was referencing a saved search. Anyway - since I was able to construct the url already I just needed to know how to set that inside the "a href" tag. All good now, thanks both.