Save File With dialog box

I’ve scoured the forums and have come up with nothing that works.

I cannot get UXP to initiate the save function with dialog box. I simply need to save the current document to a PSD with a filename from a stored variable. I’d love to dive into persistant tokens but really to get V1.0 of the plugin done I’d settle for a session token.

It would be nice if you provided what you’ve got so far

Below is only the latest of what I’ve tried. I can get the file picker open and select a folder but when I click select folder it writes the file but doesn’t pass the filename to the file. it comes back undefinded.psd.

With my limited javascript knowledge, I’m guessing that the fileNameStore function is not finishing before the savePrintFile function is running. Below is the code I have.

please forgive the rather childish-looking code. I’m only one week in learning Javascript.

function fileSave(){

function fileNameStore(){
   console.log('step 2');
   let fileTitle = document.querySelector('#file-title').value;
   let fileSku = document.querySelector('#SKU').value;
   let fileName = (`${fileSku} ${fileTitle}`);

   if (printFileCheckLaser || printFileCheckUv || printFileCheckPrint || printFileCheckSpangle ){
      fileName = (`${fileName} -`)

   if (printFileCheckLaser === true){
      fileName = (`${fileName} LASER`);
   }else {
      PrintFIleCheckLaser = false;

   if (printFileCheckUv === true){
      fileName = (`${fileName} UV`);}
   if (printFileCheckPrint === true){
      fileName = (`${fileName} PRINTING`)}
   if (printFileCheckSpangle === true){
      fileName = (`${fileName} SPANGLE`);}

   console.log(`File Name:  ${fileName}`);
   document.getElementById("file-name-display").value = (fileName);
   toClipBoard = fileName;


async function savePrintFile(){
const fs = require('uxp').storage.localFileSystem;
const persistentFolder = await fs.getFolder();    
const newFile = await persistentFolder.createFile(fileName, {overwrite: true});
const saveFile = await fs.createSessionToken(newFile);

const batchPlay = require("photoshop").action.batchPlay;

const result = await batchPlay(
      _obj: 'save',
      as: {
         _obj: 'photoshop35Format',
         maximizeCompatibility: true
      in: {
         _kind: 'local',
         _path: saveFile
      documentID: 561,
      lowerCase: true,
      _options: {
         dialogOptions: 'dontDisplay'
   synchronousExecution: false,
   modalBehavior: 'wait'

.addEventListener("click", fileSave);

Turns out my fileName variable wasn’t global. Fixed that and all is well!