- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2023 05:16 AM
Hello,
I need to fill an array in a SOAP-Request:
s.setStringParameterNoEscape('item.AddInfoAttribute', 'SAPProcessType');
s.setStringParameterNoEscape('item.AddInfoValue', 'YMIN');
But how is to achieve this in an array?
Thanks in advance!
Sven
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2023 06:16 AM
Hi @Sven Brose ,
Variables don't only have to be placed within the xml elements. The elements themselves can be within variables too. For instance:
<IctAdditionalInfos>
<!--Zero or more repetitions:-->
<item>
<Guid>INC12345</Guid>
<ParentGuid>irbert566</ParentGuid>
<AddInfoAttribute>SAPMessageImpact</AddInfoAttribute>
<AddInfoValue>50</AddInfoValue>
</item>
${items}
</IctAdditionalInfos>
With that now you can build your xml from an array into the needed xml:
The following is an idea since I don't know how your data is coming in. I am assuming it's an array of objects containing the necessary values.
var whereverDataComesFrom = [
{
"AddInfoAttribute": "SAPProcessType",
"AddInfoValue": "YMIN"
},
{
"AddInfoAttribute": "SAPCategory",
"AddInfoValue": "YAS"
}
]
function buildXml(item){
var xml = [
"<item>",
"<AddInfoAttribute>",
item.AddInfoAttribute,
"</AddInfoAttribute>",
"<AddInfoValue>",
item.AddInfoValue,
"</AddInfoValue>",
"</item>"
]
//convert to string without commas
return xml.join("");
}
//combine all your items into a string of xml
var itemsArr = whereverDataComesFrom.map(buildXml).join("");
...
s.setStringParameterNoEscape('items', itemsArr);
Again that is one idea of how to do this. There probably could be a better example if you posted or described what the data structure is that holds the values.
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 03:40 AM
Hi Chris,
I've testet it, but the array will not be set in the parameter.
var itemsArr =
'<item><AddInfoAttribute>SAPProcessType</AddInfoAttribute><AddInfoValue>YMIN</AddInfoValue></item><item><AddInfoAttribute>SAPCategory</AddInfoAttribute><AddInfoValue>YAS</AddInfoValue></item>'
This is working, but only with on Attribute/Value-Pair:
Result is:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:sap-com:document:sap:soap:functions:mc-style"> <soapenv:Header/> <soapenv:Body> <urn:ProcessIncident> <IctAdditionalInfos> <!--Zero or more repetitions:--> <item> <Guid></Guid> <ParentGuid></ParentGuid> <AddInfoAttribute></AddInfoAttribute> <AddInfoValue></AddInfoValue> </item> </IctAdditionalInfos> <IctAttachments> <!-- <item> <AttachmentGuid></AttachmentGuid> <Filename></Filename> <MimeType></MimeType> <Data>cid:375667742933</Data> <Timestamp></Timestamp> <PersonId></PersonId> <Url></Url> <Language></Language> <Delete></Delete> </item>--> </IctAttachments> <IctHead> <IncidentGuid>680FC3B7975FED10310F74871153AF9F</IncidentGuid> <RequesterGuid>SERVICENOWRZS0SAPSOLUTIONMANAGER</RequesterGuid> <ProviderGuid>BF8D284C68335032E10000000A0ACCA6</ProviderGuid> <AgentId></AgentId> <ReporterId></ReporterId> <ShortDescription>Checkmk: WARN - T4 - Enterprise Alert</ShortDescription> <Priority></Priority> <Language>DE</Language> <RequestedBegin></RequestedBegin> <RequestedEnd></RequestedEnd> </IctHead> <IctId>INC0023258</IctId> <IctPersons> </IctPersons> <IctSapNotes> </IctSapNotes> <IctSolutions> </IctSolutions> <IctStatements> <!--Zero or more repetitions:--> <item> <TextType>YU99</TextType> <Texts> <!--Zero or more repetitions:--> <item><![CDATA[Host: T4 Service: Enterprise Alert Output: For testing purposes only - this check simulates a real state change and will change it´s state every hour. ]]></item> </Texts> <Timestamp></Timestamp> <PersonId></PersonId> <Language></Language> </item> </IctStatements> <IctTimestamp></IctTimestamp> <IctUrls> </IctUrls> </urn:ProcessIncident> </soapenv:Body> </soapenv:Envelope>
Still any Ideas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 07:40 AM
Hi Chris,
sorry, my mistake. I've forget to set the variable in the SOAP Message Function.
It works like a charm!
Thank you very much!