0
votes

I am reading from the documentation on openlog:

Because Server-Side JavaScript Script Libraries have no context for which component called them, you will not be able to use this to pass the component to OpenLog. Instead, if you wish to identify which component called the code, you need to pass the component into your SSJS function as a parameter.

https://wiki.openntf.org/display/XOL/Using+from+SSJS+Script+Libraries

So I have a link which calls a SSJS function that resides in a script library:

<xp:link escape="true" text="#{obj.name}" rendered="#{obj.internal eq '3'}">
        <xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="dlgAssessment"> <xp:this.action><![CDATA[#{javascript:openDialogAssessment(this);}]]></xp:this.action> </xp:eventHandler> </xp:link>

The function registers failures to openlog as followed:

function openDialogAssessment(component){
    try {       
        try{
           assessmentBean.removeAssessment("assessment");
        }catch(e){
            openLogBean.addError(e,component);
        }
//... more code
}

If I look at the log result in openlog I read:

null - Developer has passed 'this' directly from an SSJS function in Script Library /proposal.jss. Please note, SSJS Script Libraries have no context for components. You must pass the relevant component into your SSJS function as a parameter.

Can someone tell me what I am doing wrong and how I could pass the component to the function correctly?

2
Ferry is spot on. this is always the xp/xe/xc XML tag surrounding the code. I won't post an answer, instead Ferry should move his comment to an answer so he can get the credit for answering it correctly. - Paul Stephen Withers

2 Answers

2
votes

In this context 'this' is the eventHandler. An eventHandler is not a UIComponent. You should pass 'this.getParent()' (the link) in this case.

0
votes

As Ferry stated, this refers to a component, not the function. therefor the component should be provided to the ssjs function e.g. this.getParent().