P-III: Delete a CSR Attachment with Java Web Service Calls

Intended Audience: Technical Users and Administrators of Stat

Intended Subject: Delete a CSR Attachment via Java Web Service calls

Intended Reaction: Happy Stat Customers

Keywords: Stat, Web Services, Java, CSR, Attachments

Hello fellow Stat Technical Users & Administrators!

Welcome to a new year and a new series of Blog posts!

This series will focus on getting the most out of Stat integration with other systems such as keeping documents synchronized as they are added, updated or deleted in different locations or applications.

What’s the goal of this Post?

The goal of this post is to enable your technical team to quickly setup jobs for documentation synchronization across various applications and/or locations by being able to
remove a CSR attachment.

Examples of this may be:

  • When a document gets removed from a CSR, you may want to remove the document in another location or vise-versa
  • Remove Log Files, Screenshots, Change Control Visio diagrams and the like
  • Delete any attachment from a CSR.

Caution & User Reference:

If you have not worked with Stat Web Services in the past, this is not the place to begin. You’ll need to setup your environment and ensure other settings are verified.

If you are not familiar with Stat Web Services, please refer to “Appendix G: Stat Web Services” in the Stat System Administrators Guide.

You can also find sample code and further documentation on the Stat Installation CD. On the CD you will see a directory called “web_services_sample“.

In this directory is a PDF on Stat Web Services along with a Zip file called StatWS.zip The zip file contains the sample code and additional instructions on setting
up your environment and running the samples included.


Let’s Go!

For this specific post we will look at adding an attachment to a CSR.

Delete a CSR attachment:

To remove, or delete, an attachment to a CSR we need to make the following Web Service call: deleteCSRAttachments()

For this, I’m using a Java Source/Class file named = StatWSCSRAttachCalls.java, and StatWSCSRAttachCalls.class respectively.

In this class there are three calls available to me:

/* StatWSCSRAttachCalls CSR Attachment Related Calls:

1 - retrieveCSRAttachments

2 - addCSRAttachments

3 - deleteCSRAttachments


Remembering that we need to first establish a connection to the Stat Web Service as part of the process, we will pass in our User Id and Password along with the call to make.

For the test environment that would be:


My actual call is %JAXWS_RUN_COMMAND% StatWSCSRAttachCalls WIN-52C9JR1VJH7 8080 MyUserID MyPassword 3

Here’s a screenshot of the Java call running:


Let’s see the results within Stat:

Before adding a new attachment we can see the CSR currently has at least one existing attachment: (That is a prerequisite.)


After deleting the attachments we can see the CSR currently has no more attachments:


Now let’s see what’s happening in the code:

Here’s the Attachment Type Setup:

// --------------------------------------------------

// Begin AttachmentType:

<complexType name="AttachmentType">


<element name="fileId" type="xsd:long"/>

<element name="filename" type="xsd:string"/>

<element name="contentType" type="xsd:string"/>

<element name="comments" type="xsd:string"/>

<element name="content" type="xsd:base64Binary" xmime:expectedContentTypes="application/octet-stream"/>



// End AttachmentType
// --------------------------------------------------

Here’s the call: *1, *2

%JAXWS_RUN_COMMAND% StatWSCSRAttachCalls WIN-52C9JR1VJH7 8080 MyUserID MyPassword 3


public static void main(String[] args) throws Exception {


… Set Variables and the like…


case 3: // Do deleteCSRAttachments:

// ===================================================================================

// 3 = deleteCSRAttachments(long connectId, String sdcd, long csrId, List<Long> fileId) throws WSCsrFault;

// Users will call this method to delete attachments from an existing CSR in Stat. File Ids may be retrieved by calling the retreiveCSRAttachments method.

// Server will throw an exception in case of an invalid Service Domain, or CSR Id parameters.

// Server will throw an exception if another user has the lock on the CSR.

// Server will throw an exception user has restriction to the Application.

// Server will throw an exception if CSR is in a Closed Status and user does not have proper rights.

// Server will throw an exception if CSR is assigned to another user and the current user does not have proper override rights.

// Server will throw an exception if user does not have proper right to delete Attachments.

// Server will throw an exception if the attachment list is empty.

// Before updating the CSR, a row is inserted into CSR_LOCK_STATUS and is removed after the update.

// CSR History records are inserted for deleted attachments.

// Input Parameters:

// connectId – A valid connect Id obtained by calling WSLoginService.connect.

// sdcd – Service Domain

// csrId – CSR Id

// fileId – List of file Ids for attachments.

// Return Parameter:

// void - No Return Value.

// ===================================================================================

System.out.println(" ");

System.out.println("Call #" + calltorun + ": deleteCSRAttachments...");

System.out.println(" ");


try {

// --------------------------------------------------

// Create AttachmentType attachments:

List<AttachmentType> attList = new ArrayList<AttachmentType>();

AttachmentType att = new AttachmentType();


// ---------------------------------------------------------------

// Before you can Delete the CSR Attachment, you need to get the specific File ID Number from the CSR.

// Get the File ID to Delete - Retrieve from retrieveCSRAttachments().

List<Long> attFIDList = new ArrayList<Long>();

Long attFileIdList;


// Retrieve CSR Attachments:

attList = csrPort.retrieveCSRAttachments(connectId, sdcd, csrId);


// Check for No Attachments Found:

if (attList.size() < 1) {


System.out.println(" No Attachments Found for CSR ID: " + csrId );





// ---------------------------------------------------------------

// Get CSR Attachment Information to att AttachmentType list.

att = attList.get(1);


System.out.println(" CSR ID: " + csrId + " Attachment Count Is " + attList.size() + " File(s). File #1 Name: " + att.getFilename() + ", File #1's FileID: " + att.getFileId() + ".");

// System.out.println("========================================================================================================");


// ---------------------------------------------------------------

// Do Call: This will DELETE ALL FILES ATTACHED to the CSR:

csrPort.deleteCSRAttachments(connectId, sdcd, csrId, attList);


System.out.println(" Delete Attachments for CSR ID: " + csrId + " Completed Successfully.");


} catch(WSCsrFault e) {

WSCsrFaultType ue = e.getFaultInfo();

// ---------------------------------------------------------------

// Weed out 'No Rows Returned/Affected' as Non-Error.

String strOrig = ue.getMessage();

int intIndex = strOrig.indexOf("NoResultException");

System.out.println(" ");

if(intIndex == - 1){

System.out.println("ERROR: Call = deleteCSRAttachments. Error = " + ue.getMessage());




System.out.println(" Delete Attachments for CSR ID: " + csrId + " = NO Rows Affected.");



System.out.println(" ");



default: // Do Nothing - Incorrect Call Value Passed.


System.out.println("- WARNING: Invalid Call Number Passed In. Check Calling File. Exiting Code Without Error...");



} // end switch (calltorun)

System.out.println(" ");

System.out.println("Java Web Service Call Completed Successfully.");

System.out.println(" ");



And that’s it!

With less than 100 lines of code we set and established a connection to Stat, we then removed an attachment in our CSR, taking into consideration error control and user feedback/output.

The above code set is not a complete standalone app. With the proper imports, variables, and a few other wrappers, it would still not be more than 100 lines or so.

*1 If you would like a copy of the sample code used here, please see the Documents section of the Stat User Community.

*2 I do not profess to be a pro at Java, but more of a Java noob. Please excuse any blatant coding mishaps.

One more key point:

With all processes and activities that are done within Stat or through the Stat Web Service calls – All activities are captured for Auditing and Reporting as you can see in the following:

In Closing…

In the next post we will move on to another area of Stat Web Services. Stay Tuned!

Thank you for taking the time to read this post. I hope you found it informative.



William R. Hart

Solutions Architect


Dell | Quest Group, Pre-Sales