RTTSoftware Support Forum

PDF Explorer => General => Topic started by: Padanges on September 05, 2016, 01:13:39 PM

Title: Tips on "Custom Scripts" JS syntax
Post by: Padanges on September 05, 2016, 01:13:39 PM
Hi,
can we access/verify the field name specified by a string in such a manner:

Code: [Select]
Metadata.prototype.FieldEntry = function (fieldName) {
     if (typeof this.fieldName !== 'undefined') {
        return (this.fieldName);
     }
} // prottype

var rowId = 0;
var SpecifiedFieldName = 'PDFECustom11';

pdfe.echo(pdfe.SelectedFiles(rowId).FieldEntry(SpecifiedFieldName));

or, more roughly:

Code: [Select]
var rowId = 0;
var SpecifiedFieldName = 'PDFECustom11';
if (typeof pdfe.SelectedFiles(rowId).Metadata.SpecifiedfieldName !== 'undefined') {
   pdfe.echo('specified field exists in current DB');
}

in your post (http://www.rttsoftware.com/forum/index.php/topic,576.msg1670/topicseen.html#msg1670 (http://www.rttsoftware.com/forum/index.php/topic,576.msg1670/topicseen.html#msg1670)) you seem to accomplish this by using switch statement and predefined (case) field name strings, but perhaps it's possible to check/access Field Path without knowing field names beforehand? And in a more elegant way, for example, by suing prototype function? I would appreciate any help on this.


Thanks in advance.
Title: Re: Tips on "Custom Scripts" JS syntax
Post by: RTT on September 06, 2016, 02:27:44 AM
can we access/verify the field name specified by a string in such a manner:

Code: [Select]
Metadata.prototype.FieldEntry = function (fieldName) {
     if (typeof this.fieldName !== 'undefined') {
        return (this.fieldName);
     }
} // prottype
These objects provided by the pdfe global root object (http://www.rttsoftware.com/Manuals/Index.htm?pageURL=PDFE/English/MyScriptsAPI.htm#PDFE) are not JavaScript objects, and so you can't do this. The same happens with almost all the other ActiveX objects you may create using the new ActiveXObject("ServerName.TypeName") directive.


Quote
or, more roughly:
Code: [Select]
var rowId = 0;
var SpecifiedFieldName = 'PDFECustom11';
if (typeof pdfe.SelectedFiles(rowId).Metadata.SpecifiedfieldName !== 'undefined') {
   pdfe.echo('specified field exists in current DB');
}
Or typeof Metadata['PDFECustom11']!== 'undefined'

Quote
in your post (http://www.rttsoftware.com/forum/index.php/topic,576.msg1670/topicseen.html#msg1670 (http://www.rttsoftware.com/forum/index.php/topic,576.msg1670/topicseen.html#msg1670)) you seem to accomplish this by using switch statement and predefined (case) field name strings, but perhaps it's possible to check/access Field Path without knowing field names beforehand? And in a more elegant way, for example, by suing prototype function? I would appreciate any help on this.
You can always get the defined metadata fields names from the pdfe.MetadataFieldsInfo collection object (http://www.rttsoftware.com/Manuals/Index.htm?pageURL=PDFE/English/MyScriptsAPI.htm#http://www.rttsoftware.com/Manuals/PDFE/English/MyScriptsAPI.htm#PDFE_MetadataFieldsInfo), as I explained at this post (http://www.rttsoftware.com/forum/index.php/topic,576.msg1666.html#msg1666), so no need to figure out if a field is defined or not by guessing its name.

The example you refer to is mapping grid layout column indexes, used internally, to the related script API metadata properties. Some column indexes are not even real properties, e.g. the file path or archive columns, so no direct connection to a metadata property.
Title: Re: Tips on "Custom Scripts" JS syntax
Post by: Padanges on September 06, 2016, 07:36:41 AM
Thanks! That's exactly what I needed:
Code: [Select]
var fieldName_str = 'PDFECustom1';
pdf.echo(pdfe.SelectedFiles(0).Metadata[fieldName_str]);
This is how we can let the user to specify a field name without using indexes.

Thank you for your API/JS object comments. That clears things up.
Title: Re: Tips on "Custom Scripts" JS syntax
Post by: RTT on September 07, 2016, 12:34:55 AM
That's standard bracket notation, one of the JavaScript property accessors (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors).
Title: Re: Tips on "Custom Scripts" JS syntax
Post by: Padanges on September 15, 2016, 08:09:45 PM
How can we get the current date and time in Custom scripts? It should be something like this (but it isn't): Date.now() ?

I'm posting this question in this thread, as it's the same JS syntax stuff. Regards.
Title: Re: Tips on "Custom Scripts" JS syntax
Post by: RTT on September 16, 2016, 04:21:43 PM
How can we get the current date and time in Custom scripts? It should be something like this (but it isn't): Date.now() ?

I'm posting this question in this thread, as it's the same JS syntax stuff. Regards.
You are coding JScript, so you just need to check the JScript language reference.
JScript Language Reference (Windows Scripting - JScript) (https://msdn.microsoft.com/en-us/library/yek4tbz0(v=vs.84).aspx)
Date Object (Windows Scripting - JScript) (https://msdn.microsoft.com/en-us/library/cd9w2te4(v=vs.84).aspx)

var now= new Date();
pdfe.echo(now);
Title: Re: Tips on "Custom Scripts" JS syntax
Post by: Padanges on September 27, 2016, 12:27:22 PM
It seems ( https://msdn.microsoft.com/en-us/library/b272f386(v=vs.84).aspx ) that we don't have variance(), stddev() statistical function methods, even though they can be used in Eval expressions syntax. Is there a way to access them using custom scripts after all?
Title: Re: Tips on "Custom Scripts" JS syntax
Post by: RTT on September 28, 2016, 04:03:48 PM
No, these grid layout dynamic columns eval expressions functions are not accessible from the active scripting scripts.
There are plenty of implementations in JavaScript you can use. Just Google it. Here is one example: https://gist.github.com/Daniel-Hug/7273430
Title: Re: Tips on "Custom Scripts" JS syntax
Post by: Padanges on September 29, 2016, 09:12:20 AM
Quote
There are plenty of implementations in JavaScript you can use. Just Google it. Here is one example: https://gist.github.com/Daniel-Hug/7273430
Thanks for the clarification. It's good to know.