• Inline evaluation error in OpenKM 6.3.0 script

  • Problems with installing OpenKM? No problemo, the solution is closer than you think.
Problems with installing OpenKM? No problemo, the solution is closer than you think.
Forum rules: Please, before asking something see the documentation wiki or use the search feature of the forum. And remember we don't have a crystal ball or mental readers, so if you post about an issue tell us which OpenKM are you using and also the browser and operating system version. For more info read How to Report Bugs Effectively.
 #40062  by hariharan.gopal
 
Hi,

I am trying to run a script in OpenKM 6.3.0. But I am getting errors as below.
Code: Select all
Sourced file: inline evaluation of: ``import javax.jcr.*; import com.openkm.core.*; import com.openkm.bean.*; impor . . . '' : Typed variable declaration : Attempt to resolve method: getUserID() on undefined variable or class name: session : at Line: 6 : in file: inline evaluation of: ``import javax.jcr.*; import com.openkm.core.*; import com.openkm.bean.*; impor . . . '' : session .getUserID ( )
The script as follows:
Code: Select all
import javax.jcr.*;
import com.openkm.core.*;
import com.openkm.bean.*;
import com.openkm.api.OKMDocument;

String userID = session.getUserID();
if (userID.equals("okmAdmin"))
    return;                     // RRRRRRRRRRRRRRRRRRRRRRReturn

String startPrefix = "2012AP";
int lengthOfPrefix = startPrefix.length(); 
int lengthOfDocPrefix = 10; // 2012APnnnn

String parentDir = com.openkm.util.FileUtils.getParent(eventNode.getPath());
if ( (parentDir.indexOf ("Native Format Documents") >= 0) || (parentDir.indexOf ("Invoices") >= 0) || (parentDir.indexOf ("Source") >= 0) || (parentDir.indexOf ("Former Numbering") >= 0) || (parentDir.indexOf ("References") >= 0) || (parentDir.indexOf ("Obselete Documents") >= 0)  ){
//    String shellCmd = "sh /home/abcd/debug.sh" + " = Special Directory " + parentDir;
//    java.lang.Process p = java.lang.Runtime.getRuntime().exec(shellCmd);
    return;                     // RRRRRRRRRRRRRRRRRRRRRRReturn
}

String parentName = parentDir.substring(10); // length of /okm:root/
String docName = com.openkm.util.FileUtils.getName(eventNode.getPath());

String parentFolderName = com.openkm.util.FileUtils.getName(parentDir);
String parentStartPrefix = parentFolderName;
if (parentFolderName.length() > lengthOfPrefix){
    parentStartPrefix = parentFolderName.substring(0,lengthOfPrefix);
}

String docNamePrefix = docName;
String parentFolderPrefix = parentFolderName;

if ((docName.length() > lengthOfDocPrefix) && (parentFolderName.length() > lengthOfDocPrefix)) {
    docNamePrefix = docName.substring(0,lengthOfDocPrefix);
    parentFolderPrefix = parentFolderName.substring(0, lengthOfDocPrefix);
}

if (eventType.equals("CREATE_FOLDER")) {
   // Prevent creation of a new document directory within another docuemnt directory
    if (parentStartPrefix.equals(startPrefix)){
        String token = JcrSessionManager.getInstance().getSystemToken();
        Session session = JcrSessionManager.getInstance().get(token);
        Node rootNode = session.getRootNode().getNode(Repository.ROOT);
    
        Node myNode = session.getNode(parentDir + "/" + docName);
        myNode.remove();
        rootNode.save();
        return;              // RRRRRRRRRRRRRRRRRRRRRRReturn
    }
    
    String userID = session.getUserID();
    String parentStr = parentName.replace(' ', '_');
    String docStr = docName.replace(' ', '_');
    String shellCmd = "sh /home/abcd/APnextDoc.sh" + " " + userID + " " + parentStr + " " + docStr;
    String docNumber;
    java.lang.Process p = java.lang.Runtime.getRuntime().exec(shellCmd);
    BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
    docNumber = stdInput.readLine();
    
    // Checlk if a new document number has been created in the XXnextdoc.sh script on the server
    if (docNumber.length() < 0){
        String token = JcrSessionManager.getInstance().getSystemToken();
        Session session = JcrSessionManager.getInstance().get(token);
        Node rootNode = session.getRootNode().getNode(Repository.ROOT);
        Node myNode = session.getNode(parentDir + "/" + docName);
        myNode.remove();
        rootNode.save();
    } else {
        session.move(eventNode.getPath(), parentDir + "/" +  docNumber + " " + docName);
        session.save();
    }
}

if (eventType.equals("CREATE_DOCUMENT")) {
    String token = JcrSessionManager.getInstance().getSystemToken();
    Session session = JcrSessionManager.getInstance().get(token);
    Node rootNode = session.getRootNode().getNode(Repository.ROOT);
    Node myNode = session.getNode(parentDir + "/" + docName);
    if (( parentFolderPrefix.length() < lengthOfDocPrefix) || (docNamePrefix.length()  < lengthOfDocPrefix) || !(parentFolderPrefix.equals(docNamePrefix))){
        myNode.remove();
        rootNode.save();
    } else if ( (parentDir.indexOf ("Decisions List") >= 0) || (parentDir.indexOf ("Follow Up Items") >= 0)  ) {
       return;
    } else {
       try { OKMDocument.getInstance().lock(null, myNode.getPath()); } 
       catch (Exception Ex) {;}
    }
}
 #40068  by jllort
 
First of all, create an script step by step.

Into the scripting are injected these variables:
systemToken
node
uuid
userId

You can see there's no session var, that was injected on older openkm version but not on 6.3.X, that's the reason why you get this error. You can use directly the var userId
print(userId);

Also I see eventNode varible, I suspect the same, you will get error on this line.

Sorry, because our actual documentation it's a big messi, we know and we're working these month ( july and august ) to finish rebuilding a new one. Our expectation is at the end of august have it.
 #40071  by hariharan.gopal
 
Hi,

I tried as below, but got the following errors.

Error Message:
Code: Select all
Sourced file: inline evaluation of: ``import javax.jcr.*; import com.openkm.core.*; import com.openkm.bean.*; impor . . . '' : Undefined argument: userId : at Line: 6 : in file: inline evaluation of: ``import javax.jcr.*; import com.openkm.core.*; import com.openkm.bean.*; impor . . . '' : ( userId )
Script:
Code: Select all
import javax.jcr.*;
import com.openkm.core.*;
import com.openkm.bean.*;
import com.openkm.api.OKMDocument;

print(userId);

About Us

OpenKM is part of the management software. A management software is a program that facilitates the accomplishment of administrative tasks. OpenKM is a document management system that allows you to manage business content and workflow in a more efficient way. Document managers guarantee data protection by establishing information security for business content.