Here's a script to see all Private Data via the Jobs Pane

Post Reply
crestbrr
Newbie
Posts: 4
Joined: Wed Mar 27, 2024 4:17 pm

Here's a script to see all Private Data via the Jobs Pane

Post by crestbrr »

Found a good use for the "Custom" column in the job pane. Because its value can be set by a script expression, you can use it to see all the private data for a given job with this script expression.

Code: Select all

async function calculateScriptExpression(s: Switch, flowElement: FlowElement, job: Job): Promise<string> {
  const dataTags: Array<{ tag: string; value: any }> = await job.getPrivateData()

  // Converts the array of tags and values into an object, e.g. [{ tag: 'foo', value: 'bar' }] -> { foo: 'bar' }
  const privateDataObject: Record<string, any> = dataTags.reduce((acc: Record<string, any>, { tag, value }) => {
    acc[tag] = value
    return acc
  }, {})

  // A set of tags that we want to ignore when processing job data (like certain system-generated tags)
  const irrelevantKeys = ['EnfocusSwitch.initiated', 'EnfocusSwitch.origin']
  irrelevantKeys.forEach((key) => delete privateDataObject[key])

  const privateDataString = JSON.stringify(privateDataObject)
  return privateDataString === '{}' ? 'No private data' : privateDataString

  // You can comment out the code above if you don't want this script being run every time you inspect the jobs pane
  return '// disabled'
}
Should hopefully make debugging a lot faster for y'all.
AllPrivateData.jpg
AllPrivateData.jpg (53.84 KiB) Viewed 18449 times
Alastair Scheuermann, Software Engineer @ Sun Print Solutions
Connect with me on LinkedIn
sander
Advanced member
Posts: 308
Joined: Wed Oct 01, 2014 8:58 am
Location: Den Bosch

Re: Here's a script to see all Private Data via the Jobs Pane

Post by sander »

That's very creative and really useful! I like it, thanks!

I already noticed: You have to be careful with this if you are clicking folders with a lot of jobs, the load time here will go up tremendously.
patej
Member
Posts: 101
Joined: Sun Nov 25, 2012 12:15 pm
Location: Helsinki, Finland

Re: Here's a script to see all Private Data via the Jobs Pane

Post by patej »

sander wrote: Fri Oct 18, 2024 8:59 am I already noticed: You have to be careful with this if you are clicking folders with a lot of jobs, the load time here will go up tremendously.
This snippet is a useful idea, but for us, unfortunately, viewing custom values in the Jobs pane is rarely useful due to the long loading times even with much fewer private datas. We usually have Jobs pane hidden and check private datas from a Board in Switch Portal, although that has other problems such as not being able to see (and sort by) the folder the files are in and not seeing private datas of several jobs at once like you can see in the Jobs pane.

Related to this snippet, we've implemented a similar thing in our scripts to help debugging by including the following line in the beginning of jobArrived():

Code: Select all

const __allPrivateDatas = (await job.getPrivateData()).sort((a, b) => a.tag.localeCompare(b.tag));
––> when debugging the script, we can easily view the values of all private datas available; even if a certain private data isn't directly needed in the script, seeing its value might help debugging a problem with another private data.
Post Reply