Browser Script: PropertySet Copy() Syntax

The author of the following post rasied a simple question.

"The following syntax to copy propertyset is not working in browser script.please let me know the correct syntax to use.

PropSet2 = PropSet1.Copy()"


The syntax is correct, but it doesn't hurt to consult the "Bible" for more details. Bookshelf confirms that the syntax is correct for Browser Script.

The example provided in bookshelf is:
var oPropSet1;
var oPropSet2;
oPropSet2 = oPropSet1.Copy();

However, the example is slightly incorrect, because the Property Set object is not instantiated.



But even if we correct it, there is still an error.



What if we try the Copy method on the destination object, and pass in the source object?



Bingo, it works.

Lets try a more substantial Property Set.


var ps=theApplication().NewPropertySet();
var psChild1=theApplication().NewPropertySet();
var psChild2=theApplication().NewPropertySet();
ps.SetType("Parent");
ps.SetValue("ParentValue");
ps.SetProperty("Mum","Georgette");
ps.SetProperty("Dad","George");
psChild1.SetType("Child 1");
psChild2.SetType("Child 2");
psChild1.SetProperty("Name","Bob");
psChild1.SetProperty("Gender","Male");
psChild2.SetProperty("Name","Jane");
psChild2.SetProperty("Gender","Female");
ps.AddChild(psChild1);
ps.AddChild(psChild2);
var ps2=theApplication().NewPropertySet();
ps2.Copy(ps);




As we would expect, the Copy method does work, but it is not correctly documented or built incorrectly, it is also inconsistent with the same object in eScript.

This test was performed on 8.1.1.5, 8.1.1.10, and the author of the original problem posted the problem back in 2008, which goes back at least 5 years. Isn’t amazing that a defect has been in the wild for so long without being detected?



3 comments:

  1. it's rectified in bookshelf v8.2 http://docs.oracle.com/cd/E16348_01/books/config_open_ui/appendix_a_API20.html#wp1232047

    I recall this can be achieved with the following
    var ps1 = theApplication().NewPropertySet;
    var ps2 = theApplication().NewPropertySet;
    ps2 = ps1;

    ReplyDelete
  2. Hi Leewn

    Thanks for the comment.

    Unfortunately the documentation is not consistent. That link is specific for 8.2 OUI, however the 8.2 API reference still shows the "other" syntax
    http://docs.oracle.com/cd/E16348_01/books/PDF/OIRef.pdf

    In the example provided above. ps2 is just pointing to ps1. The Copy method will result in two independent versions.

    ReplyDelete
  3. Hi Jason,

    You're on the ps2 pointing to ps1. Thanks.

    ReplyDelete

Comments are open to all, please make it constructive.