Running window.print() in flow

I have a server connect I need to run and in the flow I would like after it is done to compete a window.print() but I can not seem to get to work in a flow,

Does anyone have any ideas?

Hello,
How did you try to use this in the flow exactly? Do you see errors in the browser console?

Not that I can see, but I’m unsure if I have put it in the flow correctly (see below)

    <script is="dmx-flow" id="flow_print" type="text/dmx-flow"> 
meta: {
$param: [
  {type: "text", name: "id"},
  {type: "text", name: "cust_id"}
]
},
exec: {
steps: [
  {
    run: {
      action: "{{select_customer.load({cust_id: $param.cust_id});select_repair_print.load({id: $param.id})}}"
    }
  },
  {
    runJS: {function: "window.print()"}
  }
]
}
}</script>

Is this the correct way for it to be entered?

You don’t need the () on the function name in runJS however, I’ve never managed to get window functions working directly in runJS (it has been a long time since I’ve tried though). I have previously added them to a function and call that.

e.g.

function windowprint() {
window.print();
}
 <script is="dmx-flow" id="flow_print" type="text/dmx-flow"> 
meta: {
$param: [
  {type: "text", name: "id"},
  {type: "text", name: "cust_id"}
]
},
exec: {
steps: [
  {
    run: {
      action: "{{select_customer.load({cust_id: $param.cust_id});select_repair_print.load({id: $param.id})}}"
    }
  },
  {
    runJS: {function: "windowprint"}
  }
]
}
}</script>

Tried that but I seem to be getting the error

TypeError: can’t access property “apply”, window[e] is undefined

Not quite sure what is going wrong, but it is not working :frowning:

Can you post the new flow code that calls that function?

<script is="dmx-flow" id="flow_print" type="text/dmx-flow">{ 

meta: {
$param: [
{type: “text”, name: “id”},
{type: “text”, name: “cust_id”}
]
},
exec: {
steps: [
{
run: {
action: “{{select_customer.load({cust_id: $param.cust_id});select_repair_print.load({id: $param.id})}}”
}
},
{
runJS: {function: “windowprint()”}
}
]
}
}

I just tested this and it works correctly:

Add this before the closing </body> tag.

<script>
        function w_print() {
        window.print();
    }
    </script>

Then call it in the flow:

works fine.

You don’t need the () in the runJS step:

Also make sure your page is not cached - the window[e] is undefined bit suggests that the flow is still trying to load window.print() directly rather than through the function you just set up.

That worked well, I just needed to put a confirmation in there to make sure the data loaded.

A print action has been added to the browser component. You can call it using the dynamic events.

This topic was automatically closed after 26 hours. New replies are no longer allowed.