简体   繁体   中英

How to set a List value with JScript

In FileNet, using FEM or ACCE, it is possible to use JScript in order to set attributes' values to an object. The official IBM guide provides this example (for Strings):

importClass(Packages.com.filenet.api.property.Properties);
importClass(Packages.com.filenet.api.constants.RefreshMode);

function OnCustomProcess (CEObject)
{
   CEObject.refresh();
   CEObject.getProperties().putValue("DocumentTitle", "Test1");
   CEObject.save(RefreshMode.REFRESH);
}

But is it possible to do the same thing for more complex objects? I'm referring, in particular, to StringList type. There are no examples on the web, and defining a JS-like array doesn't work.

It is definitely possible to do this for more complex objects. Most of it is just following the path you would follow using Java, but changing the name of the variable types to var . Therefore the code for setting the value of a multivalue string property is as follows:

importClass(Packages.com.filenet.api.constants.RefreshMode);
importClass(Packages.com.filenet.api.core.Factory);

function OnCustomProcess (CEObject)
{
   CEObject.refresh();
   var list = Factory.StringList.createList();
   list.add("Value 1");
   list.add("Value 2");
   CEObject.getProperties().putObjectValue("TestMultiValueProperty1", list);
   CEObject.save(RefreshMode.REFRESH);
}

I often use the putObjectValue() method instead of the putValue() method because JavaScript sometimes has problems determining which type safe version of the putValue() it should use.

For a lot of examples you could go to the Global Configuration > Data Design > Add-ons section in the domain tab of the ACCE. The pre- and post-import scripts of the different Add-ons contain a lot of relevant JavaScript code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM