Use Script Task to Update Column on Read Data Result Collection

I'm creating a process that reads data and then needs to update a text column on that data by appending some new text to the existing string. I can read the data fine but the script task throws a null reference exception. Here is the simplified version of my script:

var programs = Get("ReadDataUserTask1.ResultEntityCollection");

foreach(var program in programs) {
    program.SetColumnValue("Campaign Flags", "Test");
}

return true;

The programs is null when I run the process.

Like 0

Like

7 comments

Dear Scott,

Try another approach to overcome the issue. Please read the collection of the Read Data in the following way: 

 var entities = Get<ICompositeObjectList<ICompositeObject>>("ReadDataUserTask1.ResultCompositeObjectList");

Afterwards proceed further with collection result.

Regards,

Anastasia

Anastasia Botezat,

using trying the above script, when I convert the list to string by doing:

entities.ToString());

I get  - Terrasoft.Common.CompositeObjectList`1[Terrasoft.Common.CompositeObject] (looks like the type and not the value)

Can you help?

Chani Karel,

 

There is no need to cast object to string since you can get the value from some column of the object using GetCompositeObjectColumnValue (in my case I was reading the "Full name" column value from the collection of contacts):

 

string name = GetCompositeObjectColumnValue&lt;string&gt;(contacts, "Name");

and then process the value according to your needs.

 

Best regards,

Oscar

Hi Chani Karel,

I think there are 2 things in your scripts:

1. You ReadDataUserTask1 result could be empty.

var programs = Get&lt;EntityCollection&gt;("ReadDataUserTask1.ResultEntityCollection");

Therefore, before the "foreach Loop", you really need to check if the programs is null or not. Otherwise, you might get the exception as you mentioned.

 

2. Please use the column code instead of column title to set value.

For example, in Contact there is column with code "JobTitle" and title "Full job title". If you need to set the value, you need to use the code "JobTitle".

 

regards,

 

Cheng Gong

Oscar Dylan,

using the tostring method was just to understand why I don't get the values as needed. 

What I need to do is this:

I get a list of 'contact in opportunity' by the read collection of records element. I need to get the contact as lookup  value and not as string (the Id and not name) in order to set parameters with the contacts and send email to them.

How do I do it?

Thank you.

Cheng Gong,

using the tostring method was just to understand why I don't get the values as needed. 

What I need to do is this:

I get a list of 'contact in opportunity' by the read collection of records element. I need to get the contact as lookup  value and not as string (the Id and not name) in order to set parameters with the contacts and send email to them.

How do I do it?

Thank you.

Chani Karel,

How did you end up solving this?

 

Kind regards,

Yosef

Show all comments