cancel
Showing results for 
Search instead for 
Did you mean: 

Print contract document and Contract document lock Script

Former Member
0 Kudos

Hi All,

We have two requirements :-

  1. We need a script to lock the document versions in the contract document once a contract document is approved.
  2. We need a button to print the contract document .

For the print button functionality, we have written a script, but we are not able to get the network printers and thus tthe code is dumping.

Script is :-

import com.sap.custom.clmprinter;
import javax.print.*;
import javax.print.attribute.*;

//printer = new clmprinter();
ver = doc.getDocVersions();

if(hasValue(ver))
{
iter = ver.iterator();
while(iter.hasNext())
{
  member = iter.next();
  document = member.getDoc();
}
}
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
services = PrintServiceLookup.lookupPrintServices(flavor, aset);

if (services[0] != null)
{
DocPrintJob job = null;
String printer = "Printer Name";

for(int i = 0; i < services.length;i++)
{                     
  if(services[i].getName().equalsIgnoreCase(printer))
  {
  
   job = services[i].createPrintJob();  // here we are not getting the printers on network
                     
  }
}
if(job == null)
{
  job = services[0].createPrintJob();
}
InputStream b = new BufferedInputStream(new FileInputStream(document.getFileData((SessionContextIfc) session)));
Doc document = new SimpleDoc(b, flavor, null);
job.print(document, aset);
}

Is there any configurations whichneeds to be done to get the printers or any other thing missed in the coding that should be taken care.

Also any suggestions on the 1st requirement?

Regards,

Puneet Arora

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member13619
Product and Topic Expert
Product and Topic Expert
0 Kudos

Puneet,

To answer your 2 questions:

  1. We need a script to lock the document versions in the contract document once a contract document is approved.


If your document is "fully" approved, meaning being in the executed phase your document should be locked except for some fields like signed document.  Why would you lock the document versions, you cannot change them without creating a new version.



  1. We need a button to print the contract document .


As this is a web based application in a browser you cannot initiate a print on the document with scripting, this is also security related (like you cannot write files on your local disk).  The only way I can imagine you could do it is creating a JAR and deploying it on your server which contains these functionalities and network sharing.


Erik