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("Read opportunity product.Opportunity");
var productId = Get("Read opportunity product.Product");
var delete = new Delete(userConnection)
        .From("UsrListDocuments")
        .Where("Opportunity").IsEqual(opportunityId)
        .Where("Product").IsEqual(productId);
        
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.

Thanks.

Like 0

Like

2 comments

Hello,

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 - https://academy.bpmonline.com/documents/technic-bpms/7-12/how-add-param…

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)

        .From("UsrListDocuments")

        .Where("Opportunity").IsEqual(opportunityId)

        .Where("Product").IsEqual(productId);

        

And execute it:

 delete.execute();

Tetiana Markova,

Thanks, Thetiana. It worked.

Show all comments