Hi Everyone. On a custom record I have added a "Re...
# suitescript
r
Hi Everyone. On a custom record I have added a "Refresh Page" button via UE- Before load shown below. Works well but when I tried to attach a client script in the before load i get this error
Copy code
var recordUrl = url.resolveRecord({
          recordType: newRecord.type,
          recordId: newRecord.id
        });

        form.addButton({
          id: refreshId,
          label: 'Refresh',
          functionName: 'window.open(\'' + recordUrl + '\', \'_self\')'
        });
a
just a guess but its probably parsing the code in the cs? and doesn't like that single quotes / escaping?
you should probably use backticks instead as the outside wrappers (template strings) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
r
let me try that
tried this but didn't work
Copy code
`window.open('${recordUrl}', '_self')`
i'm now trying to call the client script and have function in there that does the URL manipulation
a
you get the error when you click the button, or just from having the client script?
r
clicking the button
a
why are you writing the code in the function name? what's in your client script?
r
it was a simple page refresh so i did that before I had a client script. So I didn't need a CS
CS script is pretty basic even adding the standard CS template gave me the error
a
why not just write
functionName: 'MyRefreshFunction(recordUrl)'
and then have that function in your CS script do the window.open?
r
Yeah that's what I'm doing now moving all the logic to the client script
a
oh these were two separate pieces of dev work, but they're interacting.. got it
r
yeah my new client script seems to have broken the old button that was on the UE
a
yeah that old button thing... idk like it works but its a little hacky in my mind... still surprised it broke like this tho
r
yeah same here. I still think it might be a parsing error like you mentioned but no idea what I can do about it
a
9pm here mate, so I'm not about to dig into this anymore, I'm done for the day
good luck
r
Thanks for your inputs 🙂 C ya
b
the functionName is sadly overloaded and does different things depending on how its used
in this case, its trying to use the window key on the object returned by your clientscript
there is none, thus your error
the easy workaround here is to add the button function in the client script reurn object and then have the functionName be whatever key you chose for it
r
I ended up writing a generic "OpenPage" function and calling that from my buttons and that worked. But it was a interesting error