Jump to content

Add Project Task via API - Error: Failed to load FlowCode script


Recommended Posts

Hi.

I am trying to ADD / UPDATE project tasks using the various API functions.

I receive a similar error for both functions

API Call Status : fail
Error Returned  : Failed to load FlowCode script '\\?\D:\Hornbill\ESP Server\instances\vinci\apps\com.hornbill.core\entities\Projects\fc_ops\addProjectTask.xml'

The script i am using for the ADD task is 

## Powershell Hornbill XMLMC Module Example
## Add project task as defined in script to your Hornbill instance
## See the API documentation for a full list of supported input parameters:
## https://api.hornbill.com/apps/com.hornbill.projectmanager/ProjectTasks?op=addProjectTask

# Import Hornbill XMLMC Powershell Module
Import-Module "C:\Users\paddickb\OneDrive - Vinci Construction UK\Hornbill\powershellHornbillAPIModule-master\xmlmcModule.psm1"

# Define instance connection details & API key for session authentication
$hbInstance ="vinci"
$hbZone     = "eur"
$hbAPIKey   = "myprivatekeyisinhere"
Set-Instance -Instance $hbInstance  -Key $hbAPIKey -Zone $hbZone

# Define Project Tasks details - replace with a CSV loop
$projectID = "273"
$name = "this is a test project task"
$file = "C:\Users\paddickb\OneDrive - Vinci Construction UK\Hornbill\Scripts\statuses.json"

# Get statuses from JSON file ["Active", "Cancelled", "Completed"]
$JsonOutcomes = $file
$JsonOutcomes = $JsonOutcomes | ConvertTo-Json

# check the JSON has been loaded and is correct
Write-Host $JsonOutcomes

# Build XMLMC API call to add project task record
Add-Param "projectID" "$projectID"
Add-Param "name" "$name"
Add-Param "outcomes" "$converted"

# Invoke XMLMC call, output returned as PSObject
$xmlmcOutput = Invoke-XMLMC "apps/com.hornbill.projectmanager/Projects" "addProjectTask"

"status code: " + $xmlmcOutput.status
"New project task outcome : " + $xmlmcOutput.params.outcome
"New project task ID : " + $xmlmcOutput.params.projectTaskId

if($xmlmcOutput.status -ne "ok" -or !$xmlmcOutput.params.rowData){
    if($xmlmcOutput.status -eq "ok") {
        "No matching project task records found!"
    } else {
        # API call status not OK - return status and error to console
        "API Call Status : " + $xmlmcOutput.status
        "Error Returned  : " + $xmlmcOutput.error
    }
}

# Important! Remove XMLMC module from memory for security once XMLMC calls complete
Remove-Module xmlmcModule

I presume I am doing something wrong? Most likely to do with the validation of the "Statuses"??? 

The JSON file looks like this

[  
   "Active",
   "Cancelled",
   "Completed"
]

Any ideas? 

I really want to be able to resolve this so I can Create / Update project tasks dates and information in bulk using excel.

Many Thanks

Ben

 

 

Link to comment
Share on other sites

I should add that we will update the documentation on the project task api's as this is not clear. 

The reason the outcomes param is like this is because in the future we will be giving our customers the opportunity to create custom outcomes for their project tasks.

 

Alex

Link to comment
Share on other sites

Alex

I have ammended the JSON to the following for purpose of test

[ 	
{"outcome":"completed","text":"Completed","language":"en-GB","buttonColor":"primary","requiresReason":"false"}
]

The script has been tweaked to call this so now stands as 

## Powershell Hornbill XMLMC Module Example
## Add project task as defined in script to your Hornbill instance
## See the API documentation for a full list of supported input parameters:
## https://api.hornbill.com/apps/com.hornbill.projectmanager/ProjectTasks?op=addProjectTask

# Import Hornbill XMLMC Powershell Module
Import-Module "C:\Users\paddickb\OneDrive - Vinci Construction UK\Hornbill\powershellHornbillAPIModule-master\xmlmcModule.psm1"

# Define instance connection details & API key for session authentication
$hbInstance ="vinci"
$hbZone     = "eur"
$hbAPIKey   = "key in here"
Set-Instance -Instance $hbInstance  -Key $hbAPIKey -Zone $hbZone

# Define Project Tasks details - replace with a CSV loop
$projectID = "273"
$name = "this is a test project task"
$file = get-content "C:\Users\paddickb\OneDrive - Vinci Construction UK\Hornbill\Scripts\statuses.json"

$JsonOutcomes = $file
write-host $JsonOutcomes

# Build XMLMC API call to add project task record
Add-Param "projectID" "$projectID"
Add-Param "name" "$name"
Add-Param "outcomes" "$JsonOutcomes"

# Invoke XMLMC call, output returned as PSObject
$xmlmcOutput = Invoke-XMLMC "apps/com.hornbill.projectmanager/Projects" "addProjectTask"

"status code: " + $xmlmcOutput.status
"New project task outcome : " + $xmlmcOutput.params.outcome
"New project task ID : " + $xmlmcOutput.params.projectTaskId

if($xmlmcOutput.status -ne "ok" -or !$xmlmcOutput.params.rowData){
    if($xmlmcOutput.status -eq "ok") {
        "No matching project task records found!"
    } else {
        # API call status not OK - return status and error to console
        "API Call Status : " + $xmlmcOutput.status
        "Error Returned  : " + $xmlmcOutput.error
    }
}

# Important! Remove XMLMC module from memory for security once XMLMC calls complete
Remove-Module xmlmcModule

I still recieve "Error Returned  : Failed to load FlowCode script '\\?\D:\Hornbill\ESP Server\instances\vinci\apps\com.hornbill.core\entities\Projects\fc_ops\addProjectTask.xml'"

Any further ideas?

Thanks

Link to comment
Share on other sites

@Ben Paddick I can only assume that this is a fault with our powershell module because if the error being returned is this:

: Failed to load FlowCode script '\\?\D:\Hornbill\ESP Server\instances\vinci\apps\com.hornbill.core\entities\Projects\fc_ops\addProjectTask.xml'"

It can only mean that the app path is hardcoded to com.hornbill.core when it should be configurable to allow you to inject an app, which in this case would translate to com.hornbill.projectmanager.

I will raise this internally and reply to this thread when I have an update.

 

Alex

Link to comment
Share on other sites

@Ben Paddick I should have spotted this sooner:

You need the ProjectTasks entity and not the Projects entity. So 

# Invoke XMLMC call, output returned as PSObject $xmlmcOutput = Invoke-XMLMC "apps/com.hornbill.projectmanager/Projects" "addProjectTask"

should be:

# Invoke XMLMC call, output returned as PSObject $xmlmcOutput = Invoke-XMLMC "apps/com.hornbill.projectmanager/ProjectTasks" "addProjectTask"

 

I will ask internally about changing the error message to better reflect the issue.

 

Alex

  • Like 1
Link to comment
Share on other sites

@AlexTumber 

Ok the API now responds correctly (thanks). However its not yet able to create a task. It responds with "the specified project task does not exist".

If I use the projectID value returned to me within getProject it returns "failure - the specified project task does not exist".

So I presume its either a permissions issue or me supplying an incorrect projectID value. The last sems hard to believe as its a only 3 digit value ("277").

The projectID I am using is the value within H_ID returned by during addProject. I am the project manager on the project so should have relevant permissions.

Any  ideas?

Thanks

  • Like 1
Link to comment
Share on other sites

FYI - This is the latest version of the script 

## Powershell Hornbill XMLMC Module Example
## Add project task as defined in script to your Hornbill instance
## See the API documentation for a full list of supported input parameters:
## https://api.hornbill.com/apps/com.hornbill.projectmanager/ProjectTasks?op=addProjectTask

# Import Hornbill XMLMC Powershell Module
Import-Module "C:\Users\paddickb\OneDrive - Vinci Construction UK\Hornbill\powershellHornbillAPIModule-master\xmlmcModule.psm1"

# Define instance connection details & API key for session authentication
$hbInstance ="vinci"
$hbZone     = "eur"
$hbAPIKey   = "mykey"
Set-Instance -Instance $hbInstance  -Key $hbAPIKey -Zone $hbZone

# Define Project Tasks details - replace with values from CSV file later
$projectID = "277"
$TaskName = "this is a test project task"
$file = get-content "C:\Users\paddickb\OneDrive - Vinci Construction UK\Hornbill\Scripts\statuses.json"

# Check the JSON values are correct on screen
$JsonOutcomes = $file
write-host $JsonOutcomes

# Build XMLMC API call to add project task record
Add-Param "projectID" "$projectID"
Add-Param "name" "$TaskName"
Add-Param "outcomes" "$JsonOutcomes"

# Invoke XMLMC call, output returned as PSObject
$xmlmcOutput = Invoke-XMLMC "apps/com.hornbill.projectmanager/ProjectTasks" "addProjectTask"

 if($xmlmcOutput.status -eq "ok") {

         "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
        "API Status: " + $xmlmcOutput.Status
        "API Outcome: " + $xmlmcOutput.params.outcome
        "New project task ID : " + $xmlmcOutput.params.projectTaskId
        "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"

}

else {
        # API call status not OK - return status and error to console
        "API Call Status : " + $xmlmcOutput.status
        "Error Returned  : " + $xmlmcOutput.error
    }

# Important! Remove XMLMC module from memory for security once XMLMC calls complete
Remove-Module xmlmcModule

 

Link to comment
Share on other sites

@Ben Paddick sorry to hear this is still causing issues.

When you say:

On 1/25/2019 at 4:41 PM, Ben Paddick said:

However its not yet able to create a task. It responds with "the specified project task does not exist".

I'm slightly confused as to when api you are calling. Can you confirm how many api calls you are making and in which order?

 

Alex

Link to comment
Share on other sites

@AlexTumber

Hi Alex - Let's start with debugging this script (GetProject) as i think the error is likely be related to why my create task fails.

Is the syntax of the projectID field valid? I still get an error "API Outcome: failure - the specified project does not exist or you have no access to it"

I presume its either a permissions issue or me supplying an incorrect projectID value. The last sems hard to believe as its a only 3 digit value ("277").

Thanks

## Powershell Hornbill XMLMC Module 
## Get Single project details from Hornbill instance
## See the API documentation for a full list of supported API input parameters:
## https://api.hornbill.com/apps/com.hornbill.projectmanager/Projects?op=getProject

# Import Hornbill XMLMC Powershell Module
Import-Module "C:\Users\paddickb\OneDrive - Vinci Construction UK\Hornbill\powershellHornbillAPIModule-master\xmlmcModule.psm1"

# Define instance connection details & API key for session authentication
$hbInstance = "vinci"
$hbZone     = "eur"
$hbAPIKey   = "mykeyis here"
Set-Instance -Instance $hbInstance  -Key $hbAPIKey -Zone $hbZone

# Build XMLMC API call

Add-Param "projectID" "277"
#Add-Param "returnBpmDetails" "1"

# Invoke XMLMC call, output returned as PSObject
$xmlmcOutput = Invoke-XMLMC "apps/com.hornbill.projectmanager/Projects" "getProject"

 if($xmlmcOutput.status -eq "ok") {
        
        # Confirm if API searched
        "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
        "API Status: " + $xmlmcOutput.Status
        "API Outcome: " + $xmlmcOutput.params.outcome
        "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
        "Projects Details: " + $xmlmcOutput.params.projectDetails
        "Projects BPM Details: " + $xmlmcOutput.params.projectBPMDetails
        "Projects Risk Details: " + $xmlmcOutput.params.projectRiskWeighting
        "Projects Total Cost Details: " + $xmlmcOutput.params.projectTotalCost
        "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"

    } 

else {
    # API call status not OK - return status and error to console
    "API Call Status : " + $xmlmcOutput.status
    "Error Returned  : " + $xmlmcOutput.error
}

# Important! Remove XMLMC module from memory for security once XMLMC calls complete
Remove-Module xmlmcModule

 

Link to comment
Share on other sites

@Ben Paddick thanks for your post. 

Ok, so I think the returned error is probably correct :-)

Which user session are you using to invoke the api and does it have the Project Portfolio Manager role?

In terms of security for project manager, you can only see and action projects that you are a stakeholder in (if you have the standard Project User role). If you have the Project Portfolio Manager role you have access to all projects.

I would suggest giving your user (who you are making the api call with) the Project Portfolio Manager role.

 

Alex

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...