How to get read data fields in script task when the type is "read the first"
Hi,
I have a business process where I need to read the read element values in a script task.
When the read element is set to "read a collection of records" I'm using the following code:
var AccountsData = Get>("ReadDataUserTask12.ResultCompositeObjectList");
var AccountData = AccountsData.First();
var AccountAddress="";
AccountData.TryGetValue("Address", out AccountAddress);
What change do I need to do when the read element is set to "read the first record"?
Thanks,
Raz
Like


string name = string.Empty;
string email = string.Empty;
Guid RecordId = Guid.Empty;
/**
* This approach should not be used in production
* Please create process parameters and set values with standard tools (i.e. Formula)
* ReadDataUserTask1 is the Code of "Read One Contact" element
*/
var re = context.Process.FindFlowElementByName("ReadDataUserTask1").GetPropertyValue("ResultEntity");
if (re.TryGetPropertyValue("Email", out object _email))
{
email = _email.ToString();
}
if (re.TryGetPropertyValue("Name", out object _name))
{
name = _name.ToString();
}
if (re.TryGetPropertyValue("Id", out object _id))
{
if(Guid.TryParse(_id.ToString(), out Guid Id))
{
RecordId = Id;
}
}
//Set values to process parameters
Set<string>("Name", name);
Set<string>("Email", email);
Set<Guid>("RecordId", RecordId);
return true;
Kirill Krylov CPA,
Hi Kirill,
I don't understand you code.
So if shouldn't use this code in production.
what should I do?
I don't manage to get the values from ResultEntry.
Thanks,
Raz
Kirill Krylov CPA,
Your code is exactly what I need if I don't want to use "get a set of records" and if I don't what to use the "Formula" process element.
Why not to use it in production?