HP SM binary attachment problem (327 Views)
Reply
Occasional Contributor
ccankaya
Posts: 4
Registered: ‎07-11-2011
Message 1 of 1 (327 Views)

HP SM binary attachment problem

  1. In HP SM – Jira integration we’ll try to send attachment file from SM Problem Management record to Jira issue. As you see jira soap script in attachment. Jira addAttachment method description is like in attachment (adress is http://docs.atlassian.com/software/jira/docs/api/rpc-jira-plugin/latest/com/atlassian/jira/rpc/soap/..., java.lang.String, java.lang.String[], byte[][]) )

 

  1. Our test script is like below;

 

 

////////////////////////////////////////

function isEmpty(o){

               var str="";

               for( var attachment in o ){

                             str+=o[attachment].stringValue;

               }

               if(str.length==0)

               {

                             return true;

               }

               else

                             return false;

}

              

               var rootcauseId="PM10611";

               var pm=new SCFile("rootcause");

               var query="id=\"" + rootcauseId + "\"";

               print(query);

               var rc=pm.doSelect(query);

               if(rc != RC_SUCCESS)

               {

                             print("Error occured when querying file: rootcause. Error Code:1" );

               }

               else{

                             var pmId=pm.id;              

                             print(pmId);

                             /*--Attachment (+) --*/

                             var attachmentObj=pm.getAttachments();

                             if(!isEmpty(attachmentObj)){

                                            var str = "";

                                            var count=0;

                                            var AttachmentNameObj=new String();                                

                                            for ( var attachment in attachmentObj )

                                            {

                                                           AttachmentNameObj[count]=attachmentObj[ attachment ].name;

                                                           print("Attachment Name: "+ attachmentObj[ attachment ].name );

                                                           print("Attachment Value: "+ attachmentObj[ attachment ].stringValue);

                                                           print("Attachment Value Length: "+ attachmentObj[ attachment].stringValue.length );

                                                           print("Attachment HREF: "+ attachmentObj[ attachment ].href );

                                                           print("Attachment Type: "+ attachmentObj[ attachment ].type);

                                                           str+= attachmentObj[ attachment ].stringValue ;

                                                           count++;                                                         

                                            }

                                            print("String Length: "+str.length);

                             }else{

                                            print("No Attachment");

                             }                           

               }

               var loginObject=lib.TTJiraIntegration.loginJira();

 

               var jiraInstance=new lib.JiraSoapServiceService.JiraSoapServiceService();

               var jiraAddAttachment=new lib.JiraSoapServiceService.addAttachmentsToIssueRequest();

               jiraAddAttachment.in0=loginObject;

               jiraAddAttachment.in1.setValue("TTS-43");          

               jiraAddAttachment.in2=AttachmentNameObj;

               jiraAddAttachment.in3=attachmentBytesObj;  //Our problem is this point, how to set our attachment to byte array?

              

               try{

                             jiraAddAttachmentResponse=jiraInstance.invoke(jiraAddAttachment);                    

                             if(jiraAddAttachmentResponse.isFault())

                             {

                                            print("SOAP Fault: "+ jiraAddAttachmentResponse.faultstring.getValue());

                             }

                             else

                             {

                                            var jiraAddAttachmentResponseValue=jiraAddAttachmentResponse.addAttachmentsToIssueReturn;

                                            print("loginReturnCode :"+jiraAddAttachmentResponse.addAttachmentsToIssueReturn.getValue());

                             }

               }                                          

               catch( e ){

                             print( e.toString() );

               }

 

Our problem is how to added our attachment to byte array in determining rule of Jira addAttachmentIssue

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.