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

How do I fix error message - undefined is not an object in script

Explorer ,
Jan 21, 2021 Jan 21, 2021

Copy link to clipboard

Copied

When I use the FrameMaker script, sometimes I receive the following error though there is no code at this line. But sometimes the script works perfectly fine. Not sure what is the issue.

 

Script Error :
Error Message: undefined is not an object
Script, Line# : C:\D\Scripts\script01.jsx, 5

 

#target framemaker
//@include "./logging.jsxlib"

var book = app.ActiveBook;

var compType = comp.ComponentType;

if(!book.ObjectValid()) 
{
    book = app.FirstOpenBook;
}	
if(book.ObjectValid())
{
    app.ActiveBook = book;
alert (comp.Name);   
    var comp = book.FirstComponentInBook;
			var current_file = comp.Name.replace(/^.*[\\\/]/, '');	
			
    
    while(comp.ObjectValid())
    {
 
        
        if(comp.ComponentType == Constants.FV_BK_FILE)
        {
			
            var doc = OpenFile(comp.Name);
			
		
            if(doc.ObjectValid()) 
            {
								var doc = app.ActiveDoc;

                                var flow = doc.MainFlowInDoc;

                                var tframe = flow.FirstTextFrameInFlow;

                                var pgf = tframe.FirstPgf;

                                var active_doc = doc.Name.replace(/^.*[\\\/]/, '');		

                                var markersNotAddedLog = new LogFile('Markers-'+[active_doc]);
		
                                var today = new Date();

                                var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();

                                var varFmt = doc.GetNamedObject (Constants.FO_VarFmt, "Manual Name");

                                var varValue = varFmt.Fmt;
                                markersAdded = 0;

                                headText(pgf);
                                function headText (textObj, doc) {

		                                var text1 = "", textItems, i;

		                                // Get a list of the strings in the text object or text range.

		                                if (textObj.constructor.name !== "TextRange") {
		                                textItems = textObj.GetText(Constants.FTI_String);
		                                }
		                                else {
		                                textItems = doc.GetTextForRange(textObj, Constants.FTI_String);

		                                }	

		                                // Concatenate the strings.
		                                for (i = 0; i < textItems.len; i += 1) {

			                                text1 += (textItems[i].sdata);

		                                }

		                                return text1; // Return the text

		                                }

		
                                if(doc.ObjectValid() == true)
                                {						
		
                                markersNotAddedLog.log("Date:" + today + "\nFile Name: " + active_doc + "\nBook Name: " + varValue + "\n-------------------------------------------------------------------------------------\n  HEADING                           NEWLINK MARKER IN DOC     \n-------------------------------------------------------------------------------------\n");

                                var bMarkerExists = false;
                                
                                while (pgf.ObjectValid())   {

                                        bMarkerExists = false;

                                        var oMarkers = pgf.GetText(Constants.FTI_MarkerAnchor);
                                         for (var i = 0; i < oMarkers.length; i++)
                                            {
                                             if (oMarkers[i].obj.MarkerText.indexOf("newlink Filename:") >= 0)
			                                 {
				                                text = oMarkers[i].obj.MarkerText;
				                                text2 = text.replace(/newlink Filename:/g,"");
				                                text = text.replace(/newlink Filename:re_/g,"");
				                                text = text.replace(/^\s+/,'').replace(/\s+$/,'');
												markersNotAddedLog.log(headText(pgf)+ "--------------------" + "'"+text+"'.");
				                                markersAdded++;	
				                                bMarkerExists = true;
				                                break;
			                                 }
			
                                            }   
                                pgf = pgf.NextPgfInFlow;


                                }

                                }


			if (markersAdded != 0)
			{
			
			alert("Successfully created marker file for: '" + active_doc + "'\n\n Click OK to proceed.");
			}			
			else if (markersAdded === 0)
			{
			alert ("No Topic Markers in '" + active_doc + "' doc." + "\n\n Click OK to proceed.");
			
			}
		 
            }

            else
            { 
                alert("Could not open: \n\n" 
                    + comp.Name
                    + "\n\nMaybe the file doesn't exist?\n\n"
                    + "We are going to delete this component now "
                    + "because we want to do a book update, but " 
                    + "it will fail with this bogus component.");
                    
                var compToDelete = comp;
                comp = comp.PrevBookComponentInDFSOrder;
                
                if(!comp.ObjectValid()) comp = comp.FirstComponentInBook;
                

                compToDelete.Delete();
            }
        }
    
        comp = comp.NextBookComponentInDFSOrder;
    }

}
else
	
    alert("No book is open or active. Cannot run the script.");
	
function OpenFile(path)
{
    var index;

    props = GetOpenDefaultParams();

      index = GetPropIndex(props, Constants.FS_AlertUserAboutFailure);
    if(index > -1) 
        props[index].propVal.ival = false;
  
    index = GetPropIndex(props, Constants.FS_FileIsInUse);
    if(index > -1) 
        props[index].propVal.ival = Constants.FV_ResetLockAndContinue;

    index = GetPropIndex(props, Constants.FS_BookIsInUse);
    if(index > -1) 
        props[index].propVal.ival = Constants.FV_ResetLockAndContinue;

    //Continue anyway if a lock cant be reset
    index = GetPropIndex(props, Constants.FS_LockCantBeReset);
    if(index > -1) 
        props[index].propVal.ival = Constants.FV_DoOK;
        
    //Let's allow the opening of MIF and XML files
    index = GetPropIndex(props, Constants.FS_DisallowMIF);
    if(index > -1) 
        props[index].propVal.ival = false;
        
    index = GetPropIndex(props, Constants.FS_DisallowXml);
    if(index > -1) 
        props[index].propVal.ival = false;
        
    //Let's allow the opening of documents from older FM versions        
    index = GetPropIndex(props, Constants.FS_FileIsOldVersion);
    if(index > -1) 
        props[index].propVal.ival = Constants.FV_DoOK;
        
    //Ignore the "changed metric" error        
    index = GetPropIndex(props, Constants.FS_FontChangedMetric);
    if(index > -1) 
        props[index].propVal.ival = Constants.FV_DoOK;

    //Ignore the "missing fonts" errors
    index = GetPropIndex(props, Constants.FS_FontNotFoundInCatalog);
    if(index > -1) 
        props[index].propVal.ival = Constants.FV_DoOK;
        
    index = GetPropIndex(props, Constants.FS_FontNotFoundInDoc);
    if(index > -1) 
        props[index].propVal.ival = Constants.FV_DoOK;
 
    //Ignore the "missing language" error
    index = GetPropIndex(props, Constants.FS_LanguageNotAvailable);
    if(index > -1) 
        props[index].propVal.ival = Constants.FV_DoOK;
        
    //Set the flag to automatically recognize the file type
    //(.fm, .xml, etc.) or at least try
    index = GetPropIndex(props, Constants.FS_OpenAsType);
    if(index > -1) 
        props[index].propVal.ival = Constants.FV_AUTORECOGNIZE;
        
    //Let's not update any text insets or xrefs upon opening       
    index = GetPropIndex(props, Constants.FS_UpdateTextReferences);
    if(index > -1) 
        props[index].propVal.ival = Constants.FV_DoNo;
         
    index = GetPropIndex(props, Constants.FS_UpdateXRefs);
    if(index > -1) 
        props[index].propVal.ival = Constants.FV_DoNo;
    
    //Let's not use any auto-recovery files, if they exist
    index = GetPropIndex(props, Constants.FS_UseRecoverFile);
    if(index > -1) 
        props[index].propVal.ival = Constants.FV_DoNo;
        
    index = GetPropIndex(props, Constants.FS_UseAutoSaveFile);
    if(index > -1) 
        props[index].propVal.ival = Constants.FV_DoNo;
    
    //If the file is in a non-writeable location, let's open it anyway.
    index = GetPropIndex(props, Constants.FS_OpenFileNotWritable);
    if(index > -1) 
        props[index].propVal.ival = Constants.FV_DoOK;

    //Ignore any missing referenced files
    index = GetPropIndex(props, Constants.FS_RefFileNotFound);
    if(index > -1) 
    props[index].propVal.ival = Constants.FV_DoOK;
        
    returnp = new PropVals();
    var file = Open(path, props, returnp);
 
    //That's it! The Open() method returns a file object if the
    //file opened, or if not, an invalid object variable. Let's send it
    //back.
    return file;
}    

alert("Script complete!");

Views

397

Translate

Translate

Report

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

New Here , Jan 22, 2021 Jan 22, 2021

Well, I think this is technically what the interpreter would consider as line 5:

 

var compType = comp.ComponentType;

 

...and I see that 'comp' is not defined anywhere. I think the script should error out at that line. Although when I test it, I get "comp is undefined" as the error.

 

Russ

Votes

Translate

Translate
Enthusiast ,
Jan 22, 2021 Jan 22, 2021

Copy link to clipboard

Copied

I think, this has nothing to do witch this script.

I suspect, that is from a script that is stuck in "registered".

Go to the script library (file-> script -> library) to see, if theres is this ominous script "C:\D\Scripts\script01.jsx

Then unregister this script.

Have a look at this post also:

https://community.adobe.com/t5/framemaker/stuck-with-notify-registered-script/m-p/8428636?page=1

Votes

Translate

Translate

Report

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
Explorer ,
Jan 22, 2021 Jan 22, 2021

Copy link to clipboard

Copied

Thank you Klaus.

I checked the script library but could not find the script01.jsx there.

Every time I restart FM, this error appears.

but when I run any other script, and then run script01.jsx, it works fine. 

Please suggest.

Votes

Translate

Translate

Report

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
Enthusiast ,
Jan 22, 2021 Jan 22, 2021

Copy link to clipboard

Copied

So this script is in this folder:

~appdata\Roaming\Adobe\FrameMaker\Nr)\startup

or

Go to the script library (file-> script -> library) and have a look at "Autorun". Delete it there

Votes

Translate

Translate

Report

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
New Here ,
Jan 22, 2021 Jan 22, 2021

Copy link to clipboard

Copied

Well, I think this is technically what the interpreter would consider as line 5:

 

var compType = comp.ComponentType;

 

...and I see that 'comp' is not defined anywhere. I think the script should error out at that line. Although when I test it, I get "comp is undefined" as the error.

 

Russ

Votes

Translate

Translate

Report

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
Enthusiast ,
Jan 22, 2021 Jan 22, 2021

Copy link to clipboard

Copied

What makes me wonder is that the error message appears at startup. This means that the cause lies in the startup directory.

On the other hand it could be a variable, that is defined globally in that script01.jsx and used by the above script.

 

Otherwise this error would appear EVERYTIME this script is launched

Votes

Translate

Translate

Report

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
Explorer ,
Jan 24, 2021 Jan 24, 2021

Copy link to clipboard

Copied

LATEST

Thank you Russ and Klaus.

I defined comp at the starting of the code before line 5 and the script is now working perfectly fine.

Votes

Translate

Translate

Report

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