PDF Explorer > General

Tips on "Custom Scripts" JS syntax

(1/2) > >>

Padanges:
Hi,
can we access/verify the field name specified by a string in such a manner:


--- Code: ---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));
--- End code ---

or, more roughly:


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

in your post (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.

RTT:

--- Quote from: Padanges on September 05, 2016, 01:13:39 PM ---can we access/verify the field name specified by a string in such a manner:


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

--- End code ---

--- End quote ---
These objects provided by the pdfe global root object 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: ---var rowId = 0;
var SpecifiedFieldName = 'PDFECustom11';
if (typeof pdfe.SelectedFiles(rowId).Metadata.SpecifiedfieldName !== 'undefined') {
   pdfe.echo('specified field exists in current DB');
}
--- End code ---

--- End quote ---
Or typeof Metadata['PDFECustom11']!== 'undefined'


--- Quote ---in your post (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.

--- End quote ---
You can always get the defined metadata fields names from the pdfe.MetadataFieldsInfo collection object, as I explained at this post, 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.

Padanges:
Thanks! That's exactly what I needed:

--- Code: ---var fieldName_str = 'PDFECustom1';
pdf.echo(pdfe.SelectedFiles(0).Metadata[fieldName_str]);
--- End code ---
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.

RTT:
That's standard bracket notation, one of the JavaScript property accessors.

Padanges:
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.

Navigation

[0] Message Index

[#] Next page

Reply

Go to full version