Error: The given key was not present in the dictionary

Hi

I am trying to take the output of a VA, modify the format using a script and then setting a custom attribute based on the output of the script.

I can get the script to run in PowerShell if i select the following:

$mobile = "07702986412)
$mobilenumber = [string]$mobile

if ($mobilenumber -ne $null)
{
$MobileZero = $mobilenumber.SubString(0,1)
$MobileBlock = $mobilenumber.SubString(1,4)
$MobileBlock1 = $mobilenumber.SubString(5,3)
$MobileBlock2 = $mobilenumber.SubString(8,3)


$CorrectedMobile = "+44 ($MobileZero) $MobileBlock $MobileBlock1 $MobileBlock2"
}

Return $CorrectedMobile

 

However when i create a script (see below) and try to trigger a workflow based on the modification of VA-UserMobile i get the following error in the event logs "At line: 3 char:1. Exception calling "SavedObjectProperties" with "1" argument(s): "The given key was not present in the dictionary." 

function GenerateMobileNumber($Request)
{
$mobile = $workflow.SavedObjectProperties("UserDetails").get("VA-UserMobile")
$mobilenumber = [string]$mobile

if ($mobilenumber -ne $null)
{
$MobileZero = $mobilenumber.SubString(0,1)
$MobileBlock = $mobilenumber.SubString(1,4)
$MobileBlock1 = $mobilenumber.SubString(5,3)
$MobileBlock2 = $mobilenumber.SubString(8,3)


$CorrectedMobile = "+44 ($MobileZero) $MobileBlock $MobileBlock1 $MobileBlock2"
}

Return $CorrectedMobile

}

Does anyone have any ideas on how I can fix this issue? 

thanks