Deleting records on Script Task process element

Hello community,

I am trying to perform the following command from a Script Task element:

DELETE FROM [dbo].[UsrListDocuments] WHERE [Opportunity] = @P1 AND [Product] = @P2

Currently, the C# code is similar to this:

var opportunityId = Get<int>("Read opportunity product.Opportunity");
var productId = Get<int>("Read opportunity product.Product");
var delete = new Delete(userConnection)
return true;

Is this accurate? What would be the best practice in this case? The code is not working properly that´s why I am looking for your assistance.





As far as I understood your business goal, you are trying to fetch some parameters via [Read Data] element in your script task and pass it further to the Delete query.

Firstly, you need to get parameters in the [Script Task] from the [Read Data] element.
For the interpreted process the algorithm is the next:
1) Create a business process parameters and map it to the needed Read Data element. You can learn more about business parameters in our guide -…
In your example it will be something like:
[#Read opportunity product.First item of resulting collection.Opportunity#] and [#Read opportunity product.First item of resulting collection.Product#]
2) Use business-parameters in your Script-task.
var opportunityId = Get<Guid>("ProcessParam1");
var productId = Get<Guid>("ProcessParam2");

Then you need to get the userConnection in order to pass it in the Delete query:

var userConnection = Get<UserConnection>("UserConnection"); 

After that you can create a delete query:

var delete = new Delete(userConnection)
And execute it:


Tetiana Markova,

Thanks, Thetiana. It worked.

Log in or register to comment