Home > Forum > Actions > Clearing itemlist content via action

Clearing itemlist content via action
0

Hello,

I am trying to clear the contents of a technical itemlist which I use to put data into a word document. This itemlist works as a buffer and takes the rows of another itemslist which have with a YES/NO field selected as YES. The source itemlist always has different values so i need to refresh the buffer. I need an easy way to clear the contents of the buffer itemlist. Also, the buffer itemlist has to be COMPLETLY empty.

I have found a solution but it leaves me a row with no data in it. The problem is i need it empty.

Thanks in advance

Best regards,
George

MVP

Hi George,


if your technical item list should always match your source item list, can't you simple use the Change type "Replace values" during save/path transition when you update the technical item list?
I'm guessing you are already using "Replace values" change type with a 'select null' statement which may create the row with no data, because you need to have the item list empty for some time.

In this case I only see a SDK Custom action as an alternative. If the technical item list could be cleared from another workflow you could use the REST API to clear the item list.
PATCH /api/data/v2.0/db/{dbId}/elements/{id}
But this won't work for the current workflow instance. This is already checked out and the REST Api can't check it out.

Best regards,
Daniel

MVP
In reply to: Aleš Jurak

Hi George

If I understand the question correctly, I used the approach where I created a data source that contains the item list values (please see picture - data source) and then configured the action as on picture in the next post.

Best regards

Aleš

That's interesting if we use a "select null" statement this leaves one row with null data. But if we use an statement which doesn't return a row at all, no new row will be added. Maybe interesting is the wrong word. I didn't think about it. Select null returns one row but without any data which could be mapped to a item list column. While a where condition which is always false return no rows at all. Therefore no row will be created.

I'm wondering if you really need the technical item list. If you only use this for a word document, you could create a data table. This could use either an SQL statement or reuse an internal view data source.

Best regards,
Daniel

In reply to: Daniel Krüger (Cosmo Consult)

That's interesting if we use a "select null" statement this leaves one row with null data. But if we use an statement which doesn't return a row at all, no new row will be added. Maybe interesting is the wrong word. I didn't think about it. Select null returns one row but without any data which could be mapped to a item list column. While a where condition which is always false return no rows at all. Therefore no row will be created.

I'm wondering if you really need the technical item list. If you only use this for a word document, you could create a data table. This could use either an SQL statement or reuse an internal view data source.

Best regards,
Daniel

Hi Daniel and Ales,

Daniel, you are right, I could have used a Datatable as the buffer itemlist that I am currently using is for read-only purposes. I didn't think of that at the time.

About the API called you mentioned, I have a question. How should the body look like? At that endpoint, as far as I am aware, you can only send new rows, not modify or delete already existing one.

Also, I found the following endpoint in the Swagger:
POST /api/data/beta/db/{dbId}/elements/{id}/itemlists/{itemlistid}/init
I have tried it but it doesn't seem to do anything. Maybe I am using it wrong. I am sending an empty JSON as a body -> {}

About the where condition that return false, that seems the way to go. I haven't really got to test it, but it seems from your sayings that it is indeed working. I will try to use this method for future projects.

Ales, thank you for your insight. Good solve to this problem!

Best regards,
George

MVP

Hello,
To delete all the rows in the list I created the following code, written in c # via the SDK actions


public class DeleteRowFromItemList : CustomAction<DeleteRowFromItemListConfig>
{
public override void Run(RunCustomActionParams args)
{

var list = args.Context.CurrentDocument.ItemsLists.GetByID(Configuration.TargetItemListId);

DeleteRowsItemList(list);

DeleteFirstRowItemList(list);

}
private void DeleteRowsItemList( WebCon.WorkFlow.SDK.Documents.Model.ItemsLists.ItemsList list)
{
int i = 1;


while (i <= list.Rows.Count() && list.Rows.Count() > 1)
{
if (i <= list.Rows.Count() && list.Rows.Count() > 1)
{
list.Rows.RemoveAt(i);
}

if (i != list.Rows.Count())
{
i++;
}
else if (i == list.Rows.Count() && list.Rows.Count() > 1)
{
i = list.Rows.Count() - 1;

}
if (i > list.Rows.Count())
{
i = list.Rows.Count() - 1;
}
}





}
private void DeleteFirstRowItemList(WebCon.WorkFlow.SDK.Documents.Model.ItemsLists.ItemsList list)
{


list.Rows.Remove(list.Rows.FirstOrDefault());


}
}