Author Topic: Document Script gives "expected ';'" Error  (Read 9003 times)

Screwtape

  • EA User
  • **
  • Posts: 93
  • Karma: +4/-0
    • View Profile
Document Script gives "expected ';'" Error
« on: January 06, 2016, 10:14:26 pm »
Hi! It's my first attempt at a Document Script fragment, and everything I've tried either gives me

Error:   
Script Error - xpected ';'   


or nothing happens.

I've copied the example from the manual, and just changed the InsertFile command to InsertText for simplicity, and added a debug line, leaving me with the following:

Code: [Select]
!INC Local Scripts.EAConstants-JScript
function main()
{
     Session.Output("Got here!");
     var reporting as EA.DocumentGenerator;
     reporting = CreateDocumentGenerator();
     if(reporting != null)
     {
          if(reporting.NewDocument(""))
          {
               if(!reporting.InsertText("This is some text"))
               {
                    Session.Output( "Error: " + reporting.GetLastError() );
               }
               return reporting.GetDocumentAsRTF();
          }
     }
}

If I don't have anything in the "Script" combobox, nothing happens. If I have a script, I get the error above. In order to make sure that the script selected didn't cause the issue, I've created an empty "Dummy" script. Still no joy. Everything I do either gives the error above, or nothing happens - i.e. no text, and no debug message.

Has anyone got this working and can anybody suggest what I'm doing wrong. I'm sure it's obvious, but just not to me.

Thanks!

Screwtape.
Screwtape

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Document Script gives "expected ';'" Error
« Reply #1 on: January 06, 2016, 10:48:20 pm »
I think the document script should go in an actual script, and you should select this script in the dropdown.
Then in the text field below you should probably call the function defined in your script; in this case

Code: [Select]
main();
In reality you'll probably need to pass the package or object id to the script. You can do this by using the macros #objectID# and #PackageID#
Check the custom script example in the learning centre, I suspect the document script mechanism will be rather similar.

Don't expect things like Session.Output to work when this script is being called from the document generation.

Geert

Screwtape

  • EA User
  • **
  • Posts: 93
  • Karma: +4/-0
    • View Profile
Re: Document Script gives "expected ';'" Error
« Reply #2 on: January 07, 2016, 12:09:50 am »
Thanks for the pointers Geert! I'd started that way, and then just kept trying every option I could think of to get the trivial example to work.

As you suggested, I moved the code into the "Dummy" script that was referenced in the drop down, and called it from the Custom Fragment as you'd suggested.

There was an error in the change I made too, as I'd missed a parameter from the InsertText field, which caused a "type mismatch" error.

The following code worked:
Code: [Select]
!INC Local Scripts.EAConstants-JScript
function main()
{
Session.Output("Got here!");
    var reporting as EA.DocumentGenerator;
    reporting = Repository.CreateDocumentGenerator();
    if(reporting != null)
    {
        Session.Output("Got here 2!");
if(reporting.NewDocument(""))
        {
            Session.Output("Got here 3!");
if(!reporting.InsertText("This is some text",""))
            {
                Session.Output( "Error: " + reporting.GetLastError() );
            }
Session.Output("Got here 4!");
var retStr;
retStr = reporting.GetDocumentAsRTF();
Session.Output("Got here 5!");
            return retStr;
          }
    }
}

At least, with your help, I've got the trivial example to work now, which is a major step forward.

Sadly, the code I was intending to use seems to cause EA to crash and shutdown.
Screwtape

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Document Script gives "expected ';'" Error
« Reply #3 on: January 07, 2016, 01:44:42 am »
Sadly, the code I was intending to use seems to cause EA to crash and shutdown.

Ahh, you have some blind debugging to do  :-\

Start small and then add steps until you get the error....

I feel your pain :-X

Geert

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Document Script gives "expected ';'" Error
« Reply #4 on: January 07, 2016, 11:37:17 pm »
Possibly not helpful, but it's a Bad IdeaTM to name any function main() when it isn't. And yours isn't. Name it for what it does, or at the very least, make sure the name is unique. It certainly won't hurt.

/Uffe
My theories are always correct, just apply them to the right reality.

Pawel Zubkiewicz

  • EA User
  • **
  • Posts: 78
  • Karma: +2/-1
    • View Profile
    • zubkiewicz.com
Re: Document Script gives "expected ';'" Error
« Reply #5 on: March 10, 2016, 03:10:20 am »
The following code worked:
Code: [Select]
!INC Local Scripts.EAConstants-JScript
function main()
{
Session.Output("Got here!");
    var reporting as EA.DocumentGenerator;
    reporting = Repository.CreateDocumentGenerator();
    if(reporting != null)
    {
        Session.Output("Got here 2!");
if(reporting.NewDocument(""))
        {
            Session.Output("Got here 3!");
if(!reporting.InsertText("This is some text",""))
            {
                Session.Output( "Error: " + reporting.GetLastError() );
            }
Session.Output("Got here 4!");
var retStr;
retStr = reporting.GetDocumentAsRTF();
Session.Output("Got here 5!");
            return retStr;
          }
    }
}

At least, with your help, I've got the trivial example to work now, which is a major step forward.

Sadly, the code I was intending to use seems to cause EA to crash and shutdown.


Your example code works for me as well, however ONLY in a case when in template I select custom section - strange - this is not described in documentation at all!

If custom section is not selected the script is not executed!
Even though this custom section does not refer to output of the script it is included in the final document.


Similarly to you, I also have problems with my intendent script. I got some errors but logs don't say much :-(
Also if I change in my script the
Code: [Select]
return docGenerator.GetDocumentAsRTF(); into
Code: [Select]
docGenerator.SaveDocument( OUTPUT_FILE, DOCUMENTATION_TYPE );
EA generates proper document with correct content.

So, my question to you Screwtape is: did you manage to find your way with this new functionality? Maybe you could share what have you learned?


PS. Geert, the Session.Output is visible (when script is actually executed of course)
PS2. I'm using newest version of EA 12.1.1228.


EDIT:

Never mind, I managed to fix the problem :-)
« Last Edit: March 10, 2016, 04:11:15 am by Pawel Zubkiewicz »
Enhanced Requirement Attributes Addin for Enterprise Architect (ERA Addin) - http://zubkiewicz.com/?p=239

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Document Script gives "expected ';'" Error
« Reply #6 on: May 04, 2016, 02:46:43 pm »
Just a quick hit for anyone looking for info on Document Script template fragments. I've got them to work, and put together a how-to list over in this post.

/Uffe
« Last Edit: May 04, 2016, 05:08:01 pm by Uffe »
My theories are always correct, just apply them to the right reality.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Document Script gives "expected ';'" Error
« Reply #7 on: May 04, 2016, 03:00:03 pm »

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Document Script gives "expected ';'" Error
« Reply #8 on: May 04, 2016, 05:08:38 pm »
Dammit.

That'll teach me to post on the forum before my morning coffee...  :-[
My theories are always correct, just apply them to the right reality.