Many of you how read my post about the security proxy concept in FileNet P8 (http://justecm.de/2020/02/using-security-proxy-for-dynamic-access-control-in-filenet-p8/) asked me how to set the security proxy property values for existing documents in a bulk job without coding a external java program. In this post I will show you how to to this with a custom java script sweep action for property templates of data type string an object.
At first you need to create a new custom sweep action in the sweep management of you object store.

Give the action a name and select “JavaScript” as the action type.

Enter the following Javascript code in the appropriate field and finish the sweep action creation.
importPackage(Packages.com.filenet.api.core);
importPackage(Packages.com.filenet.api.constants);
importPackage(Packages.com.filenet.api.exception);
importPackage(Packages.com.filenet.api.sweep);
importPackage(Packages.com.filenet.api.engine);
importPackage(Packages.com.filenet.api.property);
importPackage(Packages.com.filenet.api.util);
// Implement for custom job and queue sweeps.
function onSweep (sweepObject, sweepItems)
{
var hcc = HandlerCallContext.getInstance();
hcc.traceDetail("Entering CustomSweepHandler.onSweep");
hcc.traceDetail("sweepObject = " + sweepObject.getProperties().getIdValue(PropertyNames.ID) + "sweepItems.length = " + sweepItems.length);
// Iterate the sweepItems and change the class.
ii = 0;
for (ii = 0; ii < sweepItems.length; ii++)
{
// At the top of your loop, always check to make sure
// that the server is not shutting down.
// If it is, clean up and return control to the server.
if (hcc != null && hcc.isShuttingDown())
{
throw new EngineRuntimeException(ExceptionCode.E_BACKGROUND_TASK_TERMINATED, this.constructor.name + " is terminating prematurely because the server is shutting down");
}
var item = sweepItems[ii].getTarget();
var msg = "sweepItems[" + ii + "]= " + item.getProperties().getIdValue("ID");
hcc.traceDetail(msg);
try
{
var CEObject = com.filenet.api.core.Document (item);
var os = sweepObject.getObjectStore()
var objectId = com.filenet.api.util.Id("{5BE7719F-9B56-4183-8F5A-7D3C514FA765}");
var co = Factory.CustomObject.fetchInstance(os, objectId, null);
CEObject.getProperties().putObjectValue("SecurityTemplate", co);
CEObject.save(com.filenet.api.constants.RefreshMode.NO_REFRESH);
// Set outcome to PROCESSED if item processed successfully.
sweepItems[ii].setOutcome(SweepItemOutcome.PROCESSED,
"item processed by " + this.constructor.name);
}
// Set failure status on objects that fail to process.
catch (ioe)
{
sweepItems[ii].setOutcome(SweepItemOutcome.FAILED, "CustomSweepHandler: " +
ioe.rhinoException.getMessage());
}
}
hcc.traceDetail("Exiting CustomSweepHandler.onSweep");
}
/*
* Called automatically when the handler is invoked by a custom sweep job
* or sweep policy. Specify properties required by the handler, if any.
* If you return an empty array, then all properties are fetched.
*/
function getRequiredProperties()
{
var pnames = ['Id'];
return pnames.toString();
}
/* Implement for custom sweep policies.
* This method is not implemented because this is an example of a custom sweep job.
*/
function onPolicySweep (sweepObject, policyObject, sweepItems)
{}
The only value that needs to be adapted to your environment is in line 37 the GUID of the security proxy object that you want to pass to the documents via the sweep job and in line 39 the symbolic name of the property template in your document class.
var objectId = com.filenet.api.util.Id(“{5BE7719F-9B56-4183-8F5A-7D3C514FA765}“);
CEObject.getProperties().putObjectValue(“SecurityTemplate“, co);
So if you need to set different object values to the property templates I would recommend to create also different sweep actions. It make it afterwards a little bit more handy.
Now you can create the custom sweep job to set the object property values for all you existing documents.


Select the target class on which you want to run the sweep and select our previously created custom sweep action.

Finish the creation wizard an activate you sweep job.

That’s it now you can update the property values with bulk processing. Now I want to share with you also the Java Script code to update a string property value.
importPackage(Packages.com.filenet.api.core);
importPackage(Packages.com.filenet.api.constants);
importPackage(Packages.com.filenet.api.exception);
importPackage(Packages.com.filenet.api.sweep);
importPackage(Packages.com.filenet.api.engine);
// Implement for custom job and queue sweeps.
function onSweep (sweepObject, sweepItems)
{
var hcc = HandlerCallContext.getInstance();
hcc.traceDetail("Entering CustomSweepHandler.onSweep");
hcc.traceDetail("sweepObject = " + sweepObject.getProperties().getIdValue(PropertyNames.ID) + "sweepItems.length = " + sweepItems.length);
// Iterate the sweepItems and change the class.
ii = 0;
for (ii = 0; ii < sweepItems.length; ii++)
{
// At the top of your loop, always check to make sure
// that the server is not shutting down.
// If it is, clean up and return control to the server.
if (hcc != null && hcc.isShuttingDown())
{
throw new EngineRuntimeException(ExceptionCode.E_BACKGROUND_TASK_TERMINATED, this.constructor.name + " is terminating prematurely because the server is shutting down");
}
var item = sweepItems[ii].getTarget();
var msg = "sweepItems[" + ii + "]= " + item.getProperties().getIdValue("ID");
hcc.traceDetail(msg);
try
{
var CEObject = com.filenet.api.core.Document (item);
CEObject.getProperties().putValue("DocumentTitle","This is a custom sweep action");
CEObject.save(com.filenet.api.constants.RefreshMode.NO_REFRESH);
// Set outcome to PROCESSED if item processed successfully.
sweepItems[ii].setOutcome(SweepItemOutcome.PROCESSED,
"item processed by " + this.constructor.name);
}
// Set failure status on objects that fail to process.
catch (ioe)
{
sweepItems[ii].setOutcome(SweepItemOutcome.FAILED, "CustomSweepHandler: " +
ioe.rhinoException.getMessage());
}
}
hcc.traceDetail("Exiting CustomSweepHandler.onSweep");
}
/*
* Called automatically when the handler is invoked by a custom sweep job
* or sweep policy. Specify properties required by the handler, if any.
* If you return an empty array, then all properties are fetched.
*/
function getRequiredProperties()
{
var pnames = ['Id'];
return pnames.toString();
}
/* Implement for custom sweep policies.
* This method is not implemented because this is an example of a custom sweep job.
*/
function onPolicySweep (sweepObject, policyObject, sweepItems)
{}
To use this in you environment you just need to set up the property templates symbolic name an the string you want to pass in code line 32. The rest is straight forward and you can work around the previous guide above.
Have fun with the sweeps :-).
Over and out!
Everyone loves it whenever people get together and share thoughts. Great blog, stick with it.
If you desire to obtain a great deal from this article then youhave to apply such techniques to your won blog.
639003 170407so considerably wonderful data on here, : D. 223182
omvarega1983 The most extraordinary financial news. Klaus, you can watch a humorous approach to serious financial events in the Bayern. techempire.top
Hello There. I found your blog using msn. This is an extremely well written article. I’ll make sure to bookmark it and come back to read more of your useful information. Thanks for the post. I will definitely comeback.
chitarono1988 The most extraordinary financial news. Maximilian, you can watch a humorous approach to serious financial events in the Sachsen. marketguide.top
God gives the nuts but he does not crack them.
I’m not sure where you’re getting your information, but good topic.I needs to spend some time learning more or understanding more.Thanks for fantastic information I was looking for this information for my mission.
Very informative article post.Much thanks again. Want more.
Very informative article.Thanks Again. Keep writing.
Hey There. I found your blog using msn. This is a really well written article.I will be sure to bookmark it and return to read more ofyour useful information. Thanks for the post. I’ll certainly comeback.
Если интересна тематика про “Центр”, то рекомендуем посмотреть раздел – все про Центр.- With regards, Tiffany
Does anyone know whether I can purchase JUSTKRATOM Trainwreck Kratom Capsules (justkratomstore.com) at Tarot Labs, 2071 E West Maple Road Suite 503, Commerce Township, MI, 48390?
Если интересна тематика про “Apple”, то рекомендуем посмотреть раздел – все про Apple.- With regards, Trisha
Hey! I’m at work surfing around your blog from my new apple iphone!Just wanted to say I love reading through your blog and look forward to all your posts!Keep up the excellent work!
hey thanks for the info. appreciate the good work
Im thankful for the article post.Really thank you! Great.
A big thank you for your article post.Thanks Again. Keep writing.
A fascinating discussion is worth comment. I assume that you need to create more on this subject, it might not be a taboo subject however normally individuals are not enough to speak on such subjects. To the next. Thanks
jingpethamppi1971 The most extraordinary financial news. Erik, you can watch a humorous approach to serious financial events in the Thüringen. wealthway.top
I really liked your blog.Really thank you! Fantastic.
Thanks-a-mundo for the article.Really thank you! Really Cool.
new erectile dysfunction treatment online pharmacy store – onlinepharmaciescanada com