16 Replies Latest reply on Sep 15, 2017 6:02 AM by attil

    Job Number Variable Script...

    attil Level 1

      Sorry for reposting, but i did so in the wrong forum.

       

      I found this script for adding Job Numbers using Indesign Variables, but i was wondering if anyone knows how to get it to read the first 9 characters (numbers and letters) of the filename instead of just the first 2? Any help would be greatly appreciated.

       

      Here's what i'm trying to acheive:

      I have an indesign slug with job information in it. I want the script/variable to update a "JobNumber" text field based on the first 9 characters in the filename. Eg. 12ABC1234_client_description

       

      Thanks in advance.

       

      app.addEventListener("afterSaveAs", updateJobNumber, false);

      function updateJobNumber ()
      {
        
      if (app.activeDocument.saved)
        
      {
        varRef
      = app.activeDocument.textVariables.item("JobNumber");
        
      if (varRef.isValid)
        
      {
        fileId
      = app.activeDocument.fullName.name.match(/^\d+/);
        
      if (fileId)
        
      {
        
      if (varRef.variableOptions.contents != fileId[0])
        
      {
        varRef
      .variableOptions.contents = fileId[0];
        app
      .activeDocument.save();
        
      }
        
      }
        
      }
        
      }
      }