Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Help for fix scrip

Contributor ,
Jan 28, 2019 Jan 28, 2019

Hi experts,

my script like this:

var
  cName, mLinks, cLink, matchCount = 0,
  checkLinkName,
  manual = false;
if (cFile.name.match(/\.indb/i))
  manual = true;
  else {
   mLinks = cFile.links.everyItem().getElements();
   while (cLink = mLinks.shift()) {
     cName = cLink.name.match(/[ec]\d{4}_..\.eps/);
     if (!cName.length) continue;
     cName = cName[0].split(/_..\.eps/)[0];
     matchCount++;
     }
    if(matchCount > 1 || matchCount == 0) manual = true;
    }

if (manual)
  cName = mDialog ();

cTime = new Date;
if (!File(cPath.exists))
  Folder(cPath).create();
cName += ".pdf";
return File(cPath + cName);
}

    function mDialog ()
    {
        var
        w = new Window("dialog","Input Stock Code", undefined, {closeButton: false}),
        p = w.add("panel"),
            mLine = p.add("group"),
                mStat1 = mLine.add("statictext", undefined, "Stock code:"),
                mEdit1 = mLine.add("edittext", undefined, ""),
        mB = w.add("group");
       
        mB.add ('button', undefined, "取り消す", {name: "Cancel"});
        mB.add ('button', undefined, "OK", {name: "OK"}); 
       
        mLine.alignChildren = "left";
        mEdit1.characters = 8;
        mB.spacing = 50;

        if (w.show() == 1)
            return Number(mEdit1.text);
        else exit();          
        }

it is error on :

     if (!cName.length) continue;

How can I fix it.

Thanks

Regard

John

TOPICS
Scripting
483
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 28, 2019 Jan 28, 2019

Use

if (!cName || !cName.length) continue;

The issue is that the match method call above it can also result in a null result and accessing property on a null results in an error

-Manan

Translate
Community Expert ,
Jan 28, 2019 Jan 28, 2019

You forgot to add what the error is ...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 28, 2019 Jan 28, 2019

Hi Jongware

the error reason is:

null is not an object

John

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 28, 2019 Jan 28, 2019

Use

if (!cName || !cName.length) continue;

The issue is that the match method call above it can also result in a null result and accessing property on a null results in an error

-Manan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 28, 2019 Jan 28, 2019
LATEST

thank you Manan

thank so much.

John

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines