Welcome Serena Central users! CLICK HERE
The migration of the Serena Central community is currently underway. Be sure to read THIS MESSAGE to get your new login set up to access your account.
SwatiShah Absent Member.
Absent Member.

Re: Attachment and Webservice

Jump to solution

Hi

  I created a mulipart SOAP request using (Java API) to sent to HPSM. It was success but no attachments were attached. Log files showed the following

 E Error -1 trying to update attachment for cm3r C047XXXXX

 

cm3r is our change manaagement table

0 Likes
Absent Member.. UniMacStar Absent Member..
Absent Member..

Re: Attachment and Webservice

Jump to solution

Hi,

 

I am writing this after so much research on handling attachment with third party web service.

I have written below code in order to send attachment data to third party web service.

//Calling Incident ID by using global variable
var HPSMIncident = system.vars.$G_IncId;
//Fetching probsummary record for Incident Id
var IncidentFile = new SCFile( "probsummary" );
var findIncident = IncidentFile.doSelect( "number#\""+ HPSMIncident + "\"" );
var updatedby=IncidentFile.updated_by;
var clientIncidentId=IncidentFile.si_serv_incident_id;
var assignment=IncidentFile.assignment;
var IncidentSIDBID = IncidentFile.si_initiator_incident;
var SIBUS = IncidentFile.si_bus;
var j = "0";
var i = "0";
if (clientIncidentId!=null || assignment == "advantage" && updatedby!="siuser" )
{

var JBOSSCreateHistoryLogServSvc = new system.library.HTTPHistoryRecordServService.HTTPHistoryRecordServService();
var JBOSSCreateHistoryLogServReq = new system.library.HTTPHistoryRecordServService.createHistoryLog();
var JBOSSCreateHistoryLogServResp = new system.library.HTTPHistoryRecordServService.createHistoryLogResponse();
var IBMCreateHistoryLogServSvc = new system.library.MB_ProcessHistoryLog_MessageSetSOAP_HTTP_Service.MB_ProcessHistoryLog_MessageSetSOAP_HTTP_Service();
var IBMCreateHistoryLogServReq = new system.library.MB_ProcessHistoryLog_MessageSetSOAP_HTTP_Service.processHistoryLog();
var IBMCreateHistoryLogServResp = new system.library.MB_ProcessHistoryLog_MessageSetSOAP_HTTP_Service.processHistoryLogResponse();
var attach;
JBOSSCreateHistoryLogServReq.attachmentInfo = true;
JBOSSCreateHistoryLogServReq.attachmentData = true;
IBMCreateHistoryLogServReq.attachmentInfo = true;
IBMCreateHistoryLogServReq.attachmentData = true;
var ActivityQuery;
var ActivityTimeStamp;
var ActivityNumber;
var IncidentNumber;
var ActivityType;
var ActivityDesc;
var attachdata;
var attachname;
var SIsysmodtime;
function findLastActivity( query )
{
var ActivityFile = new SCFile( "activity" );
var findActivity = ActivityFile.doSelect( "number#\""+ query + "\"");
if ( findActivity == RC_SUCCESS )
{
ActivityNumber = ActivityFile.thenumber;
ActivityType = ActivityFile.type;
ActivityDesc = ActivityFile.description;
ActivityDesc = ActivityDesc.getText();
ActivityDesc = ActivityDesc.replace(/[""{}]/g, "");
IncidentNumber = ActivityFile.number;
return ActivityFile
}
else
{
print( "Could not find Activitys starting with " + query + ". " + RCtoString( findActivity ) );
return null
}
}

var ActivityQuery = system.vars.$G_IncId;
//calling Activity Table function
findLastActivity( ActivityQuery );
print("ActivityType"+ActivityType);
if ( ActivityType == "1" || ActivityType == "-1" || ActivityType == "0" || ActivityType == "01" || ActivityType == "00" || ActivityType == "External Update" || ActivityType == "Closed" || ActivityType == "Resolved" || ActivityType == "Open" || ActivityType == "Assignment" || ActivityType == "Reassignment" || ActivityType == "Status Change" )
{
print("This is not manual activity update");
return null
}
else
{
print("SUCCESS");
//==================Attachments Start"
var SiAttachFile = new SCFile("SYSATTACHMENTS");
var findIncidentquery="topic=\""+IncidentNumber+"\"";
var rc = SiAttachFile.doSelect(findIncidentquery);
if ( rc == RC_SUCCESS )
{
var x = new SCRecordList( 'SYSATTACHMENTS', new QueryCond('topic',LIKE, IncidentNumber));
print("Total record in the list: " + x.getCount());
//for (i in x )
//print(x[i].sysmodtime + " is the " + x.getPosition() + " record in the record list." );
for (i in x )
{
SIsysmoduser = x[i].sysmoduser;
var SIAttachAction = x[i].SIAttachAction;
print("SIAttachAction::"+SIAttachAction);
if ( SIsysmoduser != "siuser" && SIAttachAction == null )
{
print("j in loop"+j);
attachdata = x[i].filename;
attachname = x[i].data;
attachname = base64Encode(attachname);
print("attachname"+attachname);
//attachname = x[i].data;
//print("attachment of "+i+"record \n"+attachdata+"\n"+attachname);
if( SIBUS == "JBOSS_SI" )
{
if ( j == "0" )
{
print("attachment of "+i+"record \n"+attachdata+"\n"+attachname);
JBOSSCreateHistoryLogServReq.attachment1.attachmentName.setValue(attachdata);
JBOSSCreateHistoryLogServReq.attachment1.attachmentData.setValue(attachname);
x[i].SIAttachAction = 1;
print("x[i].SIAttachAction"+x[i].SIAttachAction);
x[i].doSave();
j++;
}
else if ( j == "1" )
{
print("attachment of "+i+"record \n"+attachdata+"\n"+attachname);
JBOSSCreateHistoryLogServReq.attachment2.attachmentName.setValue(attachdata);
JBOSSCreateHistoryLogServReq.attachment2.attachmentData.setValue(attachname);
x[i].SIAttachAction = 1;
print("x[i].SIAttachAction"+x[i].SIAttachAction);
x[i].doSave();
j++;
}
else if ( j == "2" )
{
print("attachment of "+i+"record \n"+attachdata+"\n"+attachname);
JBOSSCreateHistoryLogServReq.attachment3.attachmentName.setValue(attachdata);
JBOSSCreateHistoryLogServReq.attachment3.attachmentData.setValue(attachname);
x[i].SIAttachAction = 1;
print("x[i].SIAttachAction"+x[i].SIAttachAction);
x[i].doSave();
j++;
}


}
else if (SIBUS == "IBM_SI" )
{
if ( j == "0" )
{
print(j+"attachment of "+i+"record \n"+attachdata+"\n"+attachname);
IBMCreateHistoryLogServReq.attachment1.attachmentName.setValue(attachdata);
IBMCreateHistoryLogServReq.attachment1.attachmentData.setValue(attachname);
x[i].SIAttachAction = 1;
print("x[i].SIAttachAction"+x[i].SIAttachAction);
x[i].doSave();
j++
}
else if ( j == "1" )
{
print(j+"attachment of "+i+"record \n"+attachdata+"\n"+attachname);
IBMCreateHistoryLogServReq.attachment2.attachmentName.setValue(attachdata);
IBMCreateHistoryLogServReq.attachment2.attachmentData.setValue(attachname);
x[i].SIAttachAction = 1;
print("x[i].SIAttachAction"+x[i].SIAttachAction);
x[i].doSave();
j++;
}
else if ( j == "2" )
{
print(j+"attachment of "+i+"record \n"+attachdata+"\n"+attachname);
IBMCreateHistoryLogServReq.attachment3.attachmentName.setValue(attachdata);
IBMCreateHistoryLogServReq.attachment3.attachmentData.setValue(attachname);
x[i].SIAttachAction = 1;
print("x[i].SIAttachAction"+x[i].SIAttachAction);
x[i].doSave();
j++;
}
}
}


}

}
//SI Bus field mapping
if ( SIBUS == "JBOSS_SI" )
{
JBOSSCreateHistoryLogServReq.actionType.setValue("CREATE");
//print("Mapping:\n IncidentNumber:"+IncidentNumber+"\n IncidentSIDBID"+IncidentSIDBID+"\n ActivityNumber"+ActivityNumber+"\n ActivityDesc"+ActivityDesc);
JBOSSCreateHistoryLogServReq.incidentUniqueIdentifierId.setValue(IncidentNumber);
JBOSSCreateHistoryLogServReq.siUniqueID.setValue(IncidentSIDBID);
JBOSSCreateHistoryLogServReq.siUniqueTenantName.setValue("advantage");
JBOSSCreateHistoryLogServReq.initiatorHistoryLogId.setValue(ActivityNumber);
JBOSSCreateHistoryLogServReq.logType.setValue("External Update");
JBOSSCreateHistoryLogServReq.summary.setValue(ActivityDesc);
JBOSSCreateHistoryLogServReq.description.setValue(ActivityDesc);
}
else if ( SIBUS == "IBM_SI" )
{
IBMCreateHistoryLogServReq.actionType.setValue("CREATE");
//print("Mapping:\n IncidentNumber:"+IncidentNumber+"\n IncidentSIDBID"+IncidentSIDBID+"\n ActivityNumber"+ActivityNumber+"\n ActivityDesc"+ActivityDesc);
IBMCreateHistoryLogServReq.incidentUniqueIdentifierID.setValue(IncidentNumber);
IBMCreateHistoryLogServReq.SIIncidentUniqueID.setValue(IncidentSIDBID);
IBMCreateHistoryLogServReq.siUniqueTenentName.setValue("advantage");
IBMCreateHistoryLogServReq.initiatorHistoryLogId.setValue(ActivityNumber);
IBMCreateHistoryLogServReq.logType.setValue("External Update");
IBMCreateHistoryLogServReq.summary.setValue(ActivityDesc);
IBMCreateHistoryLogServReq.description.setValue(ActivityDesc);
}
else
return false

try
{
if ( SIBUS == "JBOSS_SI" )
{
var JBOSSCreateHistoryLogServResp = JBOSSCreateHistoryLogServSvc.invoke(JBOSSCreateHistoryLogServReq);
if(JBOSSCreateHistoryLogServResp.isFault())
{
throw("SOAP Fault"+JBOSSCreateHistoryLogServResp.faultstring.getValue());
}
print(JBOSSCreateHistoryLogServResp.incidentUniqueIdentifierId.getValue());
print(JBOSSCreateHistoryLogServResp.siUniqueHistoryLogId.getValue());
print(JBOSSCreateHistoryLogServResp.transactionStatus.getValue());
print(JBOSSCreateHistoryLogServResp.transactionStatusDesciption.getValue());
return JBOSSCreateHistoryLogServResp;
}
else if ( SIBUS == "IBM_SI" )
{
var IBMCreateHistoryLogServResp = IBMCreateHistoryLogServSvc.invoke(IBMCreateHistoryLogServReq);
if(IBMCreateHistoryLogServResp.isFault())
{
throw("SOAP Fault"+IBMCreateHistoryLogServResp.faultstring.getValue());
}
print("SUCCESS");
print(IBMCreateHistoryLogServResp.incidentUniqueIdentifierID.getValue());
print(IBMCreateHistoryLogServResp.SIHistoryLogId.getValue());
print(IBMCreateHistoryLogServResp.transactionStatusCode.getValue());
print(IBMCreateHistoryLogServResp.transactionStatusDesc.getValue());
return IBMCreateHistoryLogServResp;
}
}

catch(err)
{
print("Error!"+err);
return("Error!"+err);
}
}

}

 

By using above, could able to send only .txt file but not other formats. Even HP clearly stated that hadnt have any standard way to consume attachments for all the formats like .txt, .jpeg, .pdf and .xls.

 

If anybody has idea using java script, how to consume attachments. Please share with us.

 

Really it would be great helpful. Kudos added.

 

 

0 Likes
Absent Member.. abhin88 Absent Member..
Absent Member..

Re: Attachment and Webservice

Jump to solution

Hi All

 

I was wondering if we can do the same with RESTful API ? 

 

Abhinav

Kindly assign kudos if the post is helpful!
Highlighted
presidioam Trusted Contributor.
Trusted Contributor.

Re: Attachment and Webservice

Jump to solution

Thanks !

I add this working SOAP sample for Interaction Attachments:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xmime="http://www.w3.org/2005/05/xmlmime" xmlns:ns="http://schemas.hp.com/SM/7" xmlns:cmn="http://schemas.hp.com/SM/7/Common">
<soap:Body>
<ns:UpdateTLCInteractionRequest attachmentInfo="true" attachmentData="true">
<ns:model>
<ns:keys>
<ns:CallID type=""><!--TICKET--></ns:CallID>
</ns:keys>
<ns:instance>
<ns:attachments>
<cmn:attachment xmime:contentType="<!--MIMEALLEGATO-->" action="add" name="<!--NOMEALLEGATO-->" type="" attachmentType="">$b64:file(<!--PATHALLEGATO-->)$</cmn:attachment>
</ns:attachments>
</ns:instance>
</ns:model>
</ns:UpdateTLCInteractionRequest>
</soap:Body>
</soap:Envelope>

 

Replace <!--MIMEALLEGATO-->, <!--NOMEALLEGATO--> and <!--PATHALLEGATO--> with, for instance:

- application\pfd

- Module.pdf

- c:\users\checco\Module.pdf


 

Established Member.. nrobayoevo
Established Member..

Re: Attachment and Webservice

Jump to solution

how do make with http://<server>:<port>/SM/7/IncidentManagement.wsdl

I tried:

 

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://schemas.hp.com/SM/7" xmlns:com="http://schemas.hp.com/SM/7/Common" xmlns:xm="http://www.w3.org/2005/05/xmlmime">
<soapenv:Header/>
<soapenv:Body>
<ns:CreateIncidentRequest attachmentInfo="1" attachmentData="1" ignoreEmptyElements="true" updateconstraint="">
<ns:model query="">
<ns:keys query="" updatecounter="">
<!--Optional:-->
<ns:IncidentID type="String" mandatory="" readonly=""></ns:IncidentID>
</ns:keys>
<ns:instance query="" uniquequery="" recordid="" updatecounter="">
<!--Optional:-->
<ns:IncidentID type="String" mandatory="" readonly=""></ns:IncidentID>
<!--Optional:-->
<ns:Category type="String" mandatory="" readonly="">Incidente - xxx</ns:Category>
<!--Optional:-->
<ns:OpenTime type="DateTime" mandatory="" readonly=""></ns:OpenTime>
<!--Optional:-->
<ns:OpenedBy type="String" mandatory="" readonly=""></ns:OpenedBy>
<!--Optional:-->
<ns:Urgency type="String" mandatory="" readonly="">4</ns:Urgency>
<!--Optional:-->
<ns:UpdatedTime type="DateTime" mandatory="" readonly=""></ns:UpdatedTime>
<!--Optional:-->
<ns:AssignmentGroup type="String" mandatory="" readonly="">BACKOFFICE</ns:AssignmentGroup>
<!--Optional:-->
<ns:ClosedTime type="DateTime" mandatory="" readonly=""></ns:ClosedTime>
<!--Optional:-->
<ns:ClosedBy type="String" mandatory="" readonly=""></ns:ClosedBy>
<!--Optional:-->
<ns:ClosureCode type="String" mandatory="" readonly=""></ns:ClosureCode>
<!--Optional:-->
<ns:AffectedCI type="String" mandatory="" readonly="">111111111111111ns:AffectedCI>
<!--Optional:-->
<ns:Description type="Array">
<!--Zero or more repetitions:-->
<ns:Description type="String" mandatory="" readonly="">Creación caso por SOAP IU</ns:Description>
</ns:Description>
<!--Optional:-->
<ns:Solution type="Array">
<!--Zero or more repetitions:-->
<ns:Solution type="String" mandatory="" readonly=""></ns:Solution>
</ns:Solution>
<!--Optional:-->
<ns:Assignee type="String" mandatory="" readonly=""></ns:Assignee>
<!--Optional:-->
<ns:Contact type="String" mandatory="" readonly=""></ns:Contact>
<!--Optional:-->
<ns:JournalUpdates type="Array">
<!--Zero or more repetitions:-->
<ns:JournalUpdates type="String" mandatory="" readonly=""></ns:JournalUpdates>
</ns:JournalUpdates>
<!--Optional:-->
<ns:AlertStatus type="String" mandatory="" readonly=""></ns:AlertStatus>
<!--Optional:-->
<ns:ContactLastName type="String" mandatory="" readonly=""></ns:ContactLastName>
<!--Optional:-->
<ns:ContactFirstName type="String" mandatory="" readonly=""></ns:ContactFirstName>
<!--Optional:-->
<ns:Company type="String" mandatory="" readonly="">xxx</ns:Company>
<!--Optional:-->
<ns:Title type="String" mandatory="" readonly="">Caso creado por SOAP UI</ns:Title>
<!--Optional:-->
<ns:TicketOwner type="String" mandatory="" readonly=""></ns:TicketOwner>
<!--Optional:-->
<ns:UpdatedBy type="String" mandatory="" readonly=""></ns:UpdatedBy>
<!--Optional:-->
<ns:Status type="String" mandatory="" readonly=""></ns:Status>
<!--Optional:-->
<ns:Area type="String" mandatory="" readonly="">SAP</ns:Area>
<!--Optional:-->
<ns:SLAAgreementID type="Decimal" mandatory="" readonly=""></ns:SLAAgreementID>
<!--Optional:-->
<ns:SiteCategory type="String" mandatory="" readonly=""></ns:SiteCategory>
<!--Optional:-->
<ns:Subarea type="String" mandatory="" readonly="">Accesos</ns:Subarea>
<!--Optional:-->
<ns:ProblemType type="String" mandatory="" readonly=""></ns:ProblemType>
<!--Optional:-->
<ns:ResolutionFixType type="String" mandatory="" readonly=""></ns:ResolutionFixType>
<!--Optional:-->
<ns:UserPriority type="String" mandatory="" readonly=""></ns:UserPriority>
<!--Optional:-->
<ns:Location type="String" mandatory="" readonly=""></ns:Location>
<!--Optional:-->
<ns:explanation type="Array">
<!--Zero or more repetitions:-->
<ns:explanation type="String" mandatory="" readonly=""></ns:explanation>
</ns:explanation>
<!--Optional:-->
<ns:Impact type="String" mandatory="" readonly="">4</ns:Impact>
<!--Optional:-->
<ns:folder type="String" mandatory="" readonly=""></ns:folder>
<!--Optional:-->
<ns:Service type="String" mandatory="" readonly="">SAP</ns:Service>
<!--Optional:-->
<ns:attachments>
<!--Zero or more repetitions:-->
<com:attachment xm:contentType="application/pdf" href="" contentId="" action="add" name="Module.pdf" type="" len="" charset="" upload.by="" upload.date="" attachmentType="">‪C:\Users\xxx\Desktop\Module.pdf</com:attachment>
</ns:attachments>
</ns:instance>
<!--Optional:-->
<ns:messages>
<!--Zero or more repetitions:-->
<com:message type="String" mandatory="" readonly="" severity="" module=""></com:message>
</ns:messages>
</ns:model>
</ns:CreateIncidentRequest>
</soapenv:Body>
</soapenv:Envelope>

 

-------- bot no decode correctly, what is the problem???

 

Thank you.

Nestor R.

0 Likes
Geetha T Frequent Contributor.
Frequent Contributor.

Re: Attachment and Webservice

Jump to solution

Got any solution for attachment? I tried to add an attachment for existing incident , facing the same issue. The content was not decoded properly. Please post the solution.

I tried this,

import requests
import json
import re
import sys
import xml.etree.ElementTree as ET
from pprint import pprint
import sys
import xml.dom.minidom as minidom
class Add_Attachment(Action):
def run(self, WSDL_URL,USERNAME,PASSWORD,TICKET_NUMBER):
url=WSDL_URL
headers = {'Content-Type' : 'text/xml', 'SOAPAction': 'Update'}
body = '<?xml version = "1.0" encoding = "UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://schemas.hp.com/SM/7" xmlns:com="http://schemas.hp.com/SM/7/Common" xmlns:xm="http://www.w3.org/2005/05/xmlmime"><soapenv:Header/><soapenv:Body><ns:UpdateIncidentRequest attachmentInfo="true" attachmentData="true" ignoreEmptyElements="true"><ns:model query=""><ns:keys><ns:IncidentID type="String" mandatory="" readonly="">'+TICKET_NUMBER+'</ns:IncidentID></ns:keys><ns:instance query="" uniquequery="" recordid="" updatecounter=""><JournalUpdates><JournalUpdates>Attachment done by HiveCenter</JournalUpdates></JournalUpdates><ns:attachments><com:attachment name="sample.txt" action="add" href="cid:/tmp/text1.txt"></com:attachment></ns:attachments></ns:instance></ns:model></ns:UpdateIncidentRequest></soapenv:Body></soapenv:Envelope>'
response = requests.post(url,data=body,headers=headers,auth=(USERNAME, PASSWORD))
print(str(response.content)

It is adding the attachment with the given name(simple.txt) but content is not decoded properly. I tried to take the file from linux server. i am not sure how to give the file path exactly. 

 

 

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.