Unable to set user attribute with $Request.Put method in powershell script

Hello,

I'm creating users from an HR database's table and the creation is working fine, now I need to trigger an ARS wokflow that executes a script post-creation: the script is aimed to enrich user's data with information got from a CSV file that is stored on the server.

I've created the following Powershell script inside the ARS WF (triggered by Create User event):

function onPostCreate($Request) {
	$path = "C:\mypath"
	Set-Location $path
	$fname = $Request.get("givenname")
	$lname = $Request.get("sn")
    $csv = Import-Csv -Path $path\myfile.csv -Delimiter "," -Header 'Name','Surname','DATA1','DATA2','DATA3'
	foreach ($row in $csv){
		if ( ($row.name -eq $fname) -and ($row.surname -eq $lname) ) {
			$data1 = $row.'DATA1'
			$data2 = $row.'DATA2'
			$data3 = $row.'DATA3'
			$Request.put("edsva-data1",$data1)
			$Request.put("edsva-data2",$data2)
			$Request.put("mobile",$data3)
			break
		}
	}
}

This script is basically searching the just created user on the CSV file, retrieve the data from the file and write those data into the user's attributes but the command $Request.PUT isn't working. By looking at the script debug log it seems the attributes are set but when I check the values on users, they are empty.

I've managed to workaround this issue by using "Set-QADUser" instead of "$Request.Put" but I'd really like to know what I'm missing.

Thanks in advance.

Parents
  • It sounds like the script logic is fine, $Request.Put can be tricky in ARS workflows since it doesn’t always commit changes after creation. Using Set-QADUser is a good workaround, but you might also try calling $Request.Update() after $Request.Put to make sure the attributes are saved.

    Hello,

    I'm creating users from an HR database's table and the creation is working fine, now I need to trigger an ARS wokflow that executes a script post-creation: the script is aimed to enrich user's data with information got from a CSV file that is stored on the server.

    I've created the following Powershell script inside the ARS WF (triggered by Create User event):

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    function onPostCreate($Request) {
    $path = "C:\mypath"
    Set-Location $path
    $fname = $Request.get("givenname")
    $lname = $Request.get("sn")
    $csv = Import-Csv -Path $path\myfile.csv -Delimiter "," -Header 'Name','Surname','DATA1','DATA2','DATA3'
    foreach ($row in $csv){
    if ( ($row.name -eq $fname) -and ($row.surname -eq $lname) ) {
    $data1 = $row.'DATA1'
    $data2 = $row.'DATA2'
    $data3 = $row.'DATA3'
    $Request.put("edsva-data1",$data1)
    $Request.put("edsva-data2",$data2)
    $Request.put("mobile",$data3)
    break
    }
    }
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    This script is basically searching the just created user on the CSV file, retrieve the data from the file and write those data into the user's attributes but the command $Request.PUT isn't working. By looking at the script debug log it seems the attributes are set but when I check the values on users, they are empty.

    I've managed to workaround this issue by using "Set-QADUser" instead of "$Request.Put" but I'd really like to know what I'm missing.

    Thanks in advance.

Reply
  • It sounds like the script logic is fine, $Request.Put can be tricky in ARS workflows since it doesn’t always commit changes after creation. Using Set-QADUser is a good workaround, but you might also try calling $Request.Update() after $Request.Put to make sure the attributes are saved.

    Hello,

    I'm creating users from an HR database's table and the creation is working fine, now I need to trigger an ARS wokflow that executes a script post-creation: the script is aimed to enrich user's data with information got from a CSV file that is stored on the server.

    I've created the following Powershell script inside the ARS WF (triggered by Create User event):

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    function onPostCreate($Request) {
    $path = "C:\mypath"
    Set-Location $path
    $fname = $Request.get("givenname")
    $lname = $Request.get("sn")
    $csv = Import-Csv -Path $path\myfile.csv -Delimiter "," -Header 'Name','Surname','DATA1','DATA2','DATA3'
    foreach ($row in $csv){
    if ( ($row.name -eq $fname) -and ($row.surname -eq $lname) ) {
    $data1 = $row.'DATA1'
    $data2 = $row.'DATA2'
    $data3 = $row.'DATA3'
    $Request.put("edsva-data1",$data1)
    $Request.put("edsva-data2",$data2)
    $Request.put("mobile",$data3)
    break
    }
    }
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    This script is basically searching the just created user on the CSV file, retrieve the data from the file and write those data into the user's attributes but the command $Request.PUT isn't working. By looking at the script debug log it seems the attributes are set but when I check the values on users, they are empty.

    I've managed to workaround this issue by using "Set-QADUser" instead of "$Request.Put" but I'd really like to know what I'm missing.

    Thanks in advance.

Children
No Data