Web服务¶
要创建类型为 Web服务 的新动态字段,必须有一个已经运行的Web服务。它需要至少有一个类型为 Generic::PassThrough
的调用程序。将调用此调用程序从远程服务器获取数据。在请求中发送的原始数据与下面的示例类似。
{
DynamicFieldID => 123,
DynamicFieldLabel => 'NameX',
DynamicFieldName => 'NameX',
DynamicFieldValue => 'Value',
Form => {
# Form fields
# ...
},
Ticket => {
# Ticket attributes
# ...
},
DynamicField => {
NameX => 'Value'
NameY => [ 'Value' ],
},
UserID => 123,
},
Form
- 此部分包含web浏览器中当前表单中的字段。这些信息随着屏幕的填充而改变。
Ticket
此部分(或另一个源对象,例如
CustomerUser
)包含动态字段所属对象的属性。例如,在 新建电话工单 屏幕中,该部分是空的,因为还没有创建工单,但是在 工单自定义字段 屏幕中,它包含了当前工单的信息。
DynamicField
- 此部分包含当前对象的所有已配置动态字段的所有非空值。
在大多数情况下,远程服务器需要的数据与所提供的数据有很大的不同,因此强烈建议使用针对传出数据的映射模块来专门为远程服务器调用格式化数据。
以下传出映射示例显示了一个XSLT映射,该映射将丢弃任何数据并设置固定的 UserLogin
、 Password
和 TicketID``( ``TicketGet
操作需要)。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform
xmlns:xsl="https://www.w3.org/1999/XSL/Transform"
xmlns:date="https://exsalt.org/dates-and-times"
version="1.0"
extension-element-prefixes="date">
<xsl:output method="xml" encoding="utf-8" indent="yes" />
<!-- Don't return unmached tags -->
<xsl:template match="text()" />
<!-- Remove empty elements -->
<xsl:template match="*[not(node())]" />
<!-- Root template -->
<xsl:template match="/">
<RootElement>
<UserLogin>someuser</UserLogin>
<Password>somepassword</Password>
<TicketID>1</TicketID>
</RootElement>
</xsl:template>
</xsl:transform>
服务器的响应也可能非常不同,因此在这种情况下,也强烈建议对输入的数据使用映射模块,以便能够处理信息。 响应必须是键和值元素的列表。
以下传入映射示例显示了一个XSLT映射,该映射将转换来自远程服务器的 TicketGet
操作响应的结果,并根据需要提取和格式化状态和队列,以用作动态字段的选项。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform
xmlns:xsl="https://www.w3.org/1999/XSL/Transform"
xmlns:date="https://exsalt.org/dates-and-times"
version="1.0"
extension-element-prefixes="date">
<xsl:output method="xml" encoding="utf-8" indent="yes" />
<!-- Don't return unmached tags -->
<xsl:template match="text()" />
<!-- Remove empty elements -->
<xsl:template match="*[not(node())]" />
<!-- Root template -->
<xsl:template match="/">
<RootElement>
<xsl:apply-templates />
</RootElement>
</xsl:template>
<xsl:template match="/*/Ticket">
<PossibleValue>
<Key>State</Key>
<Value>
<xsl:value-of select="/*/Ticket/State" />
</Value>
</PossibleValue>
<PossibleValue>
<Key>Queue</Key>
<Value>
<xsl:value-of select="/*/Ticket/Queue" />
</Value>
</PossibleValue>
</xsl:template>
</xsl:transform>
以下Web服务定义(可导入的YAML文件)可以用于测试该字段,但是必须对端点进行调整以匹配当前系统。 该Web服务充当请求者和提供者的角色,并且始终将 TicketID
为1的状态和队列作为可能的值返回到字段。
注解
此示例不应与开发Web服务器一起使用。
---
Debugger:
DebugThreshold: debug
TestMode: '0'
Description: Dynamic Field Web Service Test
FrameworkVersion: 7.0.x git
Provider:
ErrorHandling: {}
ErrorHandlingPriority: []
Operation:
TicketGet:
Description: ''
IncludeTicketData: ''
MappingInbound: {}
MappingOutbound: {}
Type: Ticket::TicketGet
Transport:
Config:
AdditionalHeaders: ~
MaxLength: '100000000'
NameSpace: https://www.otrs.org/TicketConnector/
RequestNameFreeText: ''
RequestNameScheme: Plain
ResponseNameFreeText: ''
ResponseNameScheme: Response
Type: HTTP::SOAP
RemoteSystem: ''
Requester:
ErrorHandling: {}
ErrorHandlingPriority: []
Invoker:
TicketGet:
Description: Get possible values from the other side.
Events: []
MappingInbound:
Config:
Template: |-
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2001-2023 OTRS AG, https://otrs.com/
This software comes with ABSOLUTELY NO WARRANTY. For details, see
the enclosed file COPYING for license information (GPL). If you
did not receive this file, see https://www.gnu.org/licenses/gpl.txt.
-->
<!-- DOCUMENTATION
* Example XML Input *
<RootElement>
...
</RootElement>
* Example XML Output *
<RootElement>
<PossibleValues>
<Key>???</Key>
<Value>???</Value>
</PossibleValues>
<PossibleValues>
<Key>???</Key>
<Value>???</Value>
</PossibleValues>
...
</RootElement>
-->
<xsl:transform
xmlns:xsl="https://www.w3.org/1999/XSL/Transform"
xmlns:date="https://exslt.org/dates-and-times"
version="1.0"
extension-element-prefixes="date">
<xsl:output method="xml" encoding="utf-8" indent="yes" />
<!-- Don't return unmatched tags -->
<xsl:template match="text()" />
<!-- Remove empty elements -->
<xsl:template match="*[not(node())]" />
<!-- Root template -->
<xsl:template match="/">
<RootElement>
<xsl:apply-templates />
</RootElement>
</xsl:template>
<xsl:template match="/*/Ticket">
<PossibleValue>
<Key>State</Key>
<Value><xsl:value-of select="/*/Ticket/State" /></Value>
</PossibleValue>
<PossibleValue>
<Key>Queue</Key>
<Value><xsl:value-of select="/*/Ticket/Queue" /></Value>
</PossibleValue>
</xsl:template>
</xsl:transform>
Type: XSLT
MappingOutbound:
Config:
Template: |-
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2001-2023 OTRS AG, https://otrs.com/
This software comes with ABSOLUTELY NO WARRANTY. For details, see
the enclosed file COPYING for license information (GPL). If you
did not receive this file, see https://www.gnu.org/licenses/gpl.txt.
-->
<!-- DOCUMENTATION
* Example XML Input *
<RootElement>
...
</RootElement>
* Example XML Output *
<RootElement>
<PossibleValues>
<Key>???</Key>
<Value>???</Value>
</PossibleValues>
<PossibleValues>
<Key>???</Key>
<Value>???</Value>
</PossibleValues>
...
</RootElement>
-->
<xsl:transform
xmlns:xsl="https://www.w3.org/1999/XSL/Transform"
xmlns:date="https://exslt.org/dates-and-times"
version="1.0"
extension-element-prefixes="date">
<xsl:output method="xml" encoding="utf-8" indent="yes" />
<!-- Don't return unmatched tags -->
<xsl:template match="text()" />
<!-- Remove empty elements -->
<xsl:template match="*[not(node())]" />
<!-- Root template -->
<xsl:template match="/">
<RootElement>
<UserLogin>someuser</UserLogin>
<Password>somepassword</Password>
<TicketID>1</TicketID>
</RootElement>
</xsl:template>
</xsl:transform>
Type: XSLT
Type: Generic::PassThrough
Transport:
Config:
Encoding: ''
Endpoint: https://localhost/otrs/nph-genericinterface.pl/Webservice/GenericConfigItemConnectorSOAP
NameSpace: https://www.otrs.org/TicketConnector/
RequestNameFreeText: ''
RequestNameScheme: Plain
ResponseNameFreeText: ''
ResponseNameScheme: Response
SOAPAction: Yes
SOAPActionSeparator: '#'
SSL:
SSLProxy: ''
SSLProxyPassword: ''
SSLProxyUser: ''
Type: HTTP::SOAP
UseMappedData: '1'