Page 1 of 1

Field names with special characters

Posted: Wed Nov 08, 2017 12:35 pm
by ndeppe
I have just started dabbling with Profound.js, and I'm getting stuck with referencing field names. I have a field name called CUST# on a display. How can I reference that field in Javascript?

Here is the code that I have so far:

Code: Select all

function testdisplay() {
	pjs.defineDisplay( "display", "test/mytest.json" );
	pjs.define( "searchDS",   { type: 'ds', likeRec: {record: 'searchwin', fields: '*all' } } );
	while (!searchDS.sexit) {
		display.searchwin.execute( pjs.ds("searchDS") );
		if ( searchDS.cust# != 0 ) {   // Ain't gonna work - # isn't allowed in variable names in JavaScript
			// DO SOMETHING
		}
	}
}
exports.run = testdisplay;

Re: Field names with special characters

Posted: Wed Nov 08, 2017 2:07 pm
by ndeppe
OK, I found the answer to my own question. The fields can be accessed as an associative array, as below.

Code: Select all

function testdisplay() {
   pjs.defineDisplay( "display", "test/mytest.json" );
   pjs.define( "searchDS",   { type: 'ds', likeRec: {record: 'searchwin', fields: '*all' } } );
   while (!searchDS.sexit) {
      display.searchwin.execute( pjs.ds("searchDS") );
      if ( searchDS['cust#'] != 0 ) {   // gonna work
         // DO SOMETHING
      }
   }
}