Is it possible to have a button on a Workflow that...
# suitescript
j
Is it possible to have a button on a Workflow that redirects the user (when clicked) to the URL of a Suitelet with dynamic arguments ? e.g. /url_of_my_suitelet?id=id_of_record_where_i_clicked_button
w
Have you tried creating a workflow action script that is triggered in aftersubmit and uses the N/redirect to redirect to your suitelet?
Otherwise, I'd usually go for a UE-script that adds the button with the code to open the url.
Like @michoel suggests here: https://stackoverflow.com/a/44752359
j
I’ll try the N/redirect method
I’m hoping to achieve this via WF rather than UE, as the button should only appear when the record is locked via this already existing WF
w
I'm not saying that it works. Just thought that it might.😀
Couldn't you have logic in the UE to only display the button based on the same criteria as in the workflow?
j
I could, but trickier to maintain
if we change the criteria for record being locked, we’d have to remember to change it in two places
w
True. Let me know if you got it to work!
j
well I’ve got the button, but nothing happens when I click it, despite the fact that I’ve set up the transition to the next state which has the custom action
w
Can you see in the wf-logs that the script gets triggered in after submit?
I got it to work.
Copy code
/**
 * @NApiVersion 2.1
 * @NScriptType workflowactionscript
 */
define(['N/redirect'],

function(redirect) {

    function onAction(context) {
		log.debug('context',context)
		redirect.toSuitelet({
			deploymentId: 'customdeploy_depl_id',
			scriptId: 'customscript_script_id',
			parameters: {
				test: 19
			}
		})
    }

    return {
        onAction : onAction
    };

});
message has been deleted
The wf history looks a bit weird though. It never logs that it completes the transition to State 2. I'm guessing it is because the script redirects before it can complete.
j
So I need this to happen on View
maybe that’s why it does not work
w
This was on view
j
oh sorry in your screenshot of the add button I saw event type: edit (assume you have view also selected)
my button does nothing when clicked, other than reload the page
w
Maybe change the context for the transition to 'all'
j
ahhhh
interesting
w
Here's my transition
j
It worked!!!!
OMG OMG
thank you SOOO much
w
yay!
j
you are my hero