Question

Action Processor

  • 21 November 2022
  • 1 reply
  • 163 views

Can we get help on some functionality of action processor.

 

We would like to get the Task Description appended to Custom Field (“Field1”) in the Service Request when the Action “Commit” is apply.


1 reply

Userlevel 4
Badge +12

​I don't think this is possible exclusively through the action processor but you can probably do this through an API call triggered by the AP. I tend to use PowerShell, but I understand from IFS that you could likely use your language of choice in your scripts.

I cannot provide a polished script because we do not populate custom fields in this way. Someone like @MennovH might be able to give you a more elegant way of doing it but here is an example that might give you a spring board.

Maybe a simple trigger like...

strPowerShellAPI = [[PowerShell -ExecutionPolicy Bypass -Command "cd 'F:\Axios\WindowsPowerShell\APIScripts\'; & '.\]]


{
[[ Field concatenate on commit ]],
[[ ACT_TYPE_SC == "COMMIT"
and EVENT_TYPE == "t"]],
strPowerShellAPI .. "[INSERT SCRIPT NAME]' -myEventId $EVENT_ID -myEnvironment " .. env,
"stop"
},

Note: I use the environment to dynamically fetch the environment credentials from the base config, but you could hardcode if you aren't confident using that method.

 

Then a script looking something to like...

Param( 
[Parameter(Mandatory = $true)][String]$myEnvironment,
[Parameter(Mandatory = $true)][String]$myEventId ## Task Id
)
Process {
##set varibles
$myCreds = New-Object System.Management.Automation.PSCredential ([USERNAME],[PASSWORD])
$myGetTaskUri = "http://[INSERT YOUR IP AND PORT NUMBER FROM BASE CONFIG]/assystREST/v2/events/" + $myEventId + "?fields=*,parentEvent[*]"

## Task - GET
-------------------------------------
$taskParams = @{
"URI" = $myGetTaskUri
"Method" = 'GET'
"Credential" = $Credentials
"ContentType" = 'application/json'
}

$myGetTaskWebData = (Invoke-RestMethod @taskParams -UseBasicParsing).event
-------------------------------------

## more variables set
$myParentEventId = $myGetTaskWebData.parentEventId
$myBodyConstruct = @{
taskDescription = $myGetTaskWebData.remarks
}

## Parent - GET
-------------------------------------
$myGetParentUri = "http://[INSERT YOUR IP AND PORT NUMBER FROM BASE CONFIG]/assystREST/v2/events/" + $myParentEventId + "?fields=customFields,customFields.singleSelectValue,customFields.systemLookupValue,customFields.multiSelectValues"
$parentParams = @{
"URI" = $myGetParentUri
"Method" = 'GET'
"Credential" = $Credentials
"ContentType" = 'application/json'
}

$myGetParentWebData = (Invoke-RestMethod @parentParams -UseBasicParsing).event
-------------------------------------

## extract custom field data
$customfields = $myGetParentWebData.customFields
foreach($field in $customfields){
Switch($field.customFieldType){
1 {
## Single Line String
$value = $field.stringValue.Name
}
8 {
## Multi-line String
xxxxxxx
}
default {
## do nothing
}
}
$myBodyConstruct.($field.customFieldShortCode) = $value
}

$currentCustomFieldValue = $myBodyConstruct.[INSERT FIELD SHORTCODE]
## note that any shortCode containing special characters or spaces should be surrounded by ''
## example $myBodyConstruct.'FIELD-SHORTCODE'

$newCustomFieldValue = $currentCustomFieldValue " Task Update: " + $myBodyConstruct.taskDescription

## Custom field - PUT
$customFieldUri = ""http://[INSERT YOUR IP AND PORT NUMBER FROM BASE CONFIG]/assystREST/v2/events"

$ActionBody = @"
[INSERT ACTION JSON]
]"@

$FieldParams = @{
"URI" = $customFieldUri
"Method" = 'POST'
"Credential" = $Credentials
"ContentType" = 'application/json'
}
Invoke-RestMethod @FieldParams -Body $ActionBody -UseBasicParsing
}

A couple of notes:

  • We haven’t needed to extract the shortCode or value from a multi-line string before so I include the single-line string for reference to get you started.
  • My example extracts all custom fields and populates the myBodyConstruct variable. A bit overkill for your purpose but included because we find it so re-usable

I can provide the rest of the switch statement covering all field types but the multi-lines if want it.

{
"eventId": "$EventId",
"customFields":{
"resolvingParameters" : [
{
"parameterName" : "[INSERT FIELD ID]",
"parameterValue" : "TEST"
},
{
"parameterName" : "stringValue",
"parameterValue" : $newCustomFieldValue
}
]
}
}
 

Reply