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

Create a Bookmark containing Action/Javascript from the Console

Community Expert ,
Jul 31, 2024 Jul 31, 2024

I have this javascript that I run from the Console to create a bookmark containing an Javascript Action.

 

var root = this.bookmarkRoot;
var bookmark1 = root.createChild("Form Highlight On/Off", function() {
    app.runtimeHighlight = !app.runtimeHighlight;
});

 


The bookmark is created but, with this as javascript:

 

function() {
    app.runtimeHighlight = !app.runtimeHighlight;
}

 

I can’t figure out to not create a function, like so:

 

app.runtimeHighlight = !app.runtimeHighlight;

 

or to create a named one:

 

function bm() {
    app.runtimeHighlight = !app.runtimeHighlight;
}
bm();

 


How?

Thanks!

TOPICS
JavaScript
1.0K
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
2 ACCEPTED SOLUTIONS
Community Expert ,
Jul 31, 2024 Jul 31, 2024
var root = this.bookmarkRoot;
var bookmark1 = root.createChild("Form Highlight On/Off", 
    'app.runtimeHighlight = !app.runtimeHighlight;')

View solution in original post

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 ,
Jul 31, 2024 Jul 31, 2024
'if (app.alert({\r'+
        'cMsg: "Do you really want to clear the entire Form?",\r'+
        'cTitle: "Reset Form",\r'+
        'nIcon: 2,\r'+
        'nType: 2\r'+
    '}) == 4) {\r'+
        'this.resetForm();\r'+
    '}'

View solution in original post

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 ,
Jul 31, 2024 Jul 31, 2024
var root = this.bookmarkRoot;
var bookmark1 = root.createChild("Form Highlight On/Off", 
    'app.runtimeHighlight = !app.runtimeHighlight;')
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 ,
Jul 31, 2024 Jul 31, 2024

Thanks! I was close... 🙂

Now how can you add multiples lines code?
So instead of one line like:

var bookmark2 = root.createChild("Reset Form Fields", 'if (app.alert({cMsg: "Do you really want to clear the entire Form?",cTitle: "Reset Forms",nIcon: 2,nType: 2}) == 4) {this.resetForm();}')

It’s more lisible like so in the bookmark:

    if (app.alert({
        cMsg: "Do you really want to clear the entire Form?",
        cTitle: "Reset Form",
        nIcon: 2,
        nType: 2
    }) == 4) {
        this.resetForm();
    }

 

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 ,
Jul 31, 2024 Jul 31, 2024

Split the code between the '  ' and use return characters like this:

'line 1 blah blah blah\r'+

'line 2 kjkjkjkkjkj\r'+

'line 3 abcdefgh\r'

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 ,
Jul 31, 2024 Jul 31, 2024
'if (app.alert({\r'+
        'cMsg: "Do you really want to clear the entire Form?",\r'+
        'cTitle: "Reset Form",\r'+
        'nIcon: 2,\r'+
        'nType: 2\r'+
    '}) == 4) {\r'+
        'this.resetForm();\r'+
    '}'
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 ,
Jul 31, 2024 Jul 31, 2024

Thanks! I see I can use \n instead of \r.

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 ,
Jul 31, 2024 Jul 31, 2024
LATEST

Yes,

\n=new line

\r= carriage return

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