Accessing the JavaScript array

Text strings must be included in double quotation marks, others (object names, boolean values, numeric values etc.) need not. This also complies with the JSON format.

Here is an example that uses the contacts.create method to add phoneNumbers. According to the Cordova help, phoneNumbers is the property of contact and its data type is an array ContactField[] with three properties: type, value, & pref.

JavaScript code:

//creates a new contact
var contact = navigator.contacts.create();
//stores the contact phone numbers in ContactField[]
var phoneNumbers = [];
phoneNumbers[0] = new ContactField ('work', '212-555-1234', false);
phoneNumbers[1] = new ContactField ('mobile', '917-555-5432', true); // preferred number
phoneNumbers[2] = new ContactField ('home', '203-555-7890', false);
contact.phoneNumbers = phoneNumbers;
// save the contact
contact.save();

The corresponding PowerBuilder code (using dot notation):

oleobject.ExecJavaScript ( "var contact = navigator.contacts.create();" )
oleobject.AssociateJSwithPB ( 'contact', This )
//creates the ContactField object
oleobject.ExecJavaScript ( "var phoneNumber1 = new ContactField();" )
//associates with the object
oleobject.AssociateJSwithPB ( "phoneNumber1", this );
//sets the property values
oleobject.value = '"212-555-1234"'
oleobject.type = '"work"'
oleobject.pref = 'false'

//creates the ContactField object
oleobject.ExecJavaScript ( "var phoneNumber2 = new ContactField();" )
//associates with the object
oleobject.AssociateJSwithPB ( "phoneNumber2", this );
//sets the property values
oleobject.value = '"917-555-5432"'
oleobject.type = '"mobile"'
oleobject.pref = 'true'

//creates the ContactField object
oleobject.ExecJavaScript ( "var phoneNumber3 = new ContactField();" )
//associates with the object
oleobject.AssociateJSwithPB ( "phoneNumber3", this );
//sets the property values
oleobject.type = '"home"'
oleobject.value = '"203-555-7890"'
oleobject.pref = 'false'

//adds phoneNumbers to the newly created contact object
oleobject.AssociateJSwithPB ( "contact", this ) //associates with the contact
oleobject.phoneNumbers = '[phoneNumber1, phoneNumber2, phoneNumber3]'
oleobject.save ( "@", "@" )

The corresponding PowerBuilder code (using JSON):

oleobject.ExecJavaScript ( 'var contact = navigator.contacts.create ({"phoneNumbers":[{"type":"work","value":"212-555-1234","pref":"false"}, {"type":"mobile","value":"917-555-5432","true":"false"}, {"type":"home","value":"203-555-7890","pref":"false"}]});' )