How to read multivalued attribute in ReadResourceActivity
Hi,
I am writing a custom workflow and having trouble to read MVA in workflow coding. My workflow design looks like this
1. CurrentRequestActivity to read target, actor etc.
2. CodeActivity to initialize ActorId,ResourceId etc.
3. ReadResourceActivity (with this.ReadResourceActivity.SelectionAttributes= new string[] {"locations","profiles"};)
4. CodeActivity to access resource and their attributes
Now I have user1 with MVA called locations along with some standard attributes. I am trying to read the MVA in workflow activity#4 like this
ResourceType user = ReadResourceActivity.Resource;
object[] locs = new object[] { user["locations"] };
for (int i = 0; i < locs .Length; i++)
{
WriteToLogFile("Loction : " + i.ToString() + locs[i].ToString());
}
However this single vlaue attribute works fine...
string accountName = (string)user["AccountName"];
WriteToLogFile("AccountName : " + accountName);
My goal is to read various user assigned MVAs using workflow and push them to the database.
Your help is much appreciated.
Thanks,
Bhavesh
April 19th, 2012 2:59pm
Look at your code: you are doing two quite different things in the two cases.
In the (working) example with the single valued attribute, you are casting the value to a string:
string accountName = (string)user["AccountName"];
In the example with the multi-valued attribute, you are not casting the value, but
initializing a new object array with it:
// this is an array initialization
object[] locs1 = new object[] { user["locations"] };
// this is a cast
object[] locs2 = (object[]) user["locations"];
So, in the above example, locks2 will be an object array with one element, which is the value of the property.
Moreover, I don't think that the attribute will actually be an array, but rather an IList<string>, or IList<something>. Try checking with the debugger which is the appropriate type.
Hope this helps,
Paolo
Paolo Tedesco - http://cern.ch/idm
Free Windows Admin Tool Kit Click here and download it now
April 20th, 2012 4:08am
Thanks for your reply Paolo.
I tried following code BUT it is not working!
IList<int64> locations= (IList<int64>)user["locations"]; //because locations is int type MVA in portal
foreach (int64 location in locations)
{
WriteToLogFile("\nLocation : " + location.ToString());
}
object[] locations= (object[])user["locations"];
foreach (object location in locations)
{
WriteToLogFile("\nLocation : " + location.ToString());
}
I also gave a try removing but it didn't work.
this.ReadResourceActivity.SelectionAttributes= new string[] {"locations","profiles"};
However all of the default attributes can be readable in ReadResouceActivity
ResourceType user = FIMReadResourceActivity.Resource;
string accountName = (string)user["AccountName"];
WriteToLogFile("AccountName : " + accountName);
string DisplayName = (string)user["DisplayName"];
WriteToLogFile("\nDisplayName : " + DisplayName);
string FirstName = (string)user["FirstName"];
WriteToLogFile("\nFirstName : " + FirstName);
string LastName = (string)user["LastName"];
WriteToLogFile("\nLastName : " + LastName);
if (user["locations"] != null) // this condition evaluates true
{
IList<Int64> locations = (IList<Int64>)user["locations"]; // it results into null reference exception
object[] locations = (object[])user["locations"];// it results into null reference exception
}
I am still wondering what is wrong here!...Is there anything I need to apply on custom attributes? Why my ReadResourceActivity is NOT reading custom attributes?
Bhavesh
April 20th, 2012 11:17am
Just a thought, but does the account you're executing the ReadResourceActivity as have appropriate permissions to read the locations attribute?
Free Windows Admin Tool Kit Click here and download it now
April 22nd, 2012 6:25pm
Hi Nikki,
Thank you for your reply. I tried hardcoding Guid of Administrator as workflow ActorID but still NO success! Now I am able to read only string custom MV attributes, Not integers. Some of my MVAs are integer type so I should
not treat them as string type MVAs.
FYI...I have added couple of custom input cotrols to enter locations,profiles etc on "Edit user screen" . For example here is how I added "BhaveshIntTest" integer type MVA.
Integer type MVA RCDC configuration: Values entered in this input box IS NOT redable in workflow
<!--Sample multivalue control-->
<my:Control my:Name="BhaveshIntTest"
my:TypeName="UocCommonMultiValueControl"
my:Caption="{Binding Source=schema, Path=BhaveshIntTest.DisplayName, Mode=OneWay}"
my:Description="{Binding Source=schema, Path=BhaveshIntTest.Description, Mode=OneWay}"
my:RightsLevel="{Binding Source=rights, Path=BhaveshIntTest}">
<my:Properties>
<my:Property my:Name="Rows" my:Value="6"/>
<my:Property my:Name="Columns" my:Value="60"/>
<my:Property my:Name="DataType" my:Value="Integer"/>
<!--not supported for above property my:Value={Binding Source=schema, Path=AMultiValueString.DataType, Mode=OneWay}"/>-->
<my:Property my:Name="Value" my:Value="{Binding Source=object, Path=BhaveshIntTest, Mode=TwoWay}"/>
</my:Properties>
</my:Control>
<!--End of sample multivalue control -->
String type MVA RCDC configuration: Values entered in this input box IS redable in workflow code.
<my:Control my:Name="BhaveshStringTest"
my:TypeName="UocCommonMultiValueControl"
my:Caption="{Binding Source=schema, Path=BhaveshStringTest.DisplayName, Mode=OneWay}"
my:Description="{Binding Source=schema, Path=BhaveshStringTest.Description, Mode=OneWay}"
my:RightsLevel="{Binding Source=rights, Path=BhaveshStringTest}">
<my:Properties>
<my:Property my:Name="Rows" my:Value="3"/>
<my:Property my:Name="Columns" my:Value="60"/>
<my:Property my:Name="DataType" my:Value="String"/>
<!--not supported for above property my:Value={Binding Source=schema, Path=AMultiValueString.DataType, Mode=OneWay}"/>-->
<my:Property my:Name="Value" my:Value="{Binding Source=object, Path=BhaveshStringTest, Mode=TwoWay}"/>
</my:Properties>
</my:Control>
Thanks,
Bhavesh
April 23rd, 2012 4:09pm
All right.
I just got the success with the help of our Solution Architect. It was a datatype conversion issue.
IList<Int64> locations = (IList<Int64>)user["locations"]; // this is wrong assignment statement
IList<Nullable<Int64>> locations= (IList<Nullable<Int64>>)user["locations"];// this is CORRECT because Integer type attribute seems Nullable Int64 in portal //and I have an MVA of Integer, I have to take IList of type Nullable Int64
Thank you all for your help. MUCH APPRECIATED. :)
Bhavesh
Free Windows Admin Tool Kit Click here and download it now
April 23rd, 2012 5:08pm