In workflow there is the Append List Field Choices activity. Is there an activity to remove a value from a List Field, or is there another way to accomplish this.
In workflow there is the Append List Field Choices activity. Is there an activity to remove a value from a List Field, or is there another way to accomplish this.
Lance - There is no 'built-in' way to remove an item from a List Field in workflow. You must use a script to do this. Here is a code snippet that will do that. Note: The value of the list item to remove is being passed in by a token in this example (as opposed to 'hard-coding' it). I also made the assumption that you are using a version of workflow prior to 9.1 so I provided LFSO code. If you need RA code I can supply an example as well.
Protected Overrides Sub Execute() Try 'Get a reference to the database... Dim db as LFDatabase = Me.Database 'Get a reference to the template that contains the listfield... Dim template As LFTemplate = db.GetTemplateByName("MyNewTemplate") 'Get a reference to the listfield... Dim field As LFTemplateField = template.ItemByName("MyNewField") 'Get the value of the list item to remove... 'Note: we passed this into the script as a token... Dim itemToRemove As String = Me.GetTokenValue("ListItemToRemove") 'Step through the list items... For i As Integer = 1 To field.Count 'If the list item matches the value to remove then remove it... If field.Item(i) = itemToRemove Then field.RemoveDropDownListEntry(i) field.Update() Exit For End If Next 'Cleanup... field = Nothing template = Nothing db = Nothing Catch ex As Exception 'Pass any error messages back to workflow... WorkflowApi.TrackError(ex.Message) End Try End Sub
Let me know if this is what you were looking for...
Cliff,
Can you please supply the RA code as well?
Thanks
Here is an RA code snippet that works on my 9.11 system;
Protected Overrides Sub Execute() Try 'Get a reference to the field that contains the list... Dim myField As FieldInfo = Field.GetInfo("MyFieldName", Me.RASession) 'Instantiate a copy of the list itself... Dim fieldList As List(Of String) = myField.GetItemList 'Get the item to remove (passed in as a string token called 'ListItemToRemove'... Dim itemToRemove As String = Me.GetTokenValue("ListItemToRemove") 'Step through the list and if the item is found then remove it... For i As Integer = 0 To fieldList.Count -1 If fieldList(i) = itemToRemove Then fieldList.RemoveAt(i) Exit For End If Next 'Persist the changes... myField.SetItemList(fieldList) myField.Save() 'Cleanup... myField = Nothing fieldList = Nothing Catch ex As Exception 'Pass any error messages back to workflow... WorkflowApi.TrackError(ex.Message) End Try End Sub
Hi Ed,
I have a drop down list in Laserfiche that contains client names. When a client name changes, as in someone getting married, I need to be able to update this list with the new name and remove the old client name from Laserfiche. Utilizing LF Forms and Workflow, a user can perform two different actions:
- Add a new client name to the drop down list
- Select a name from the drop down list and change the name
The idea behind this is that end users can update a list value without having to involve a Laserfiche Administrator. Thank you for following up on this question.
Regards,
Lance
Hi Lance,
Could you provide us your use case for wanting to remove a list field value?
Thanks!
Thanks Lance. I'll add your user story to our backlog. The script Cliff suggested would get you most of the way.
Be aware that modifying the value of a list field does not retroactively change the field value for documents that have already been assigned the old value.
Hi Ed,
Thank you for the response. Built into my workflow is a query that updates all field values after a change has been made. Thank you for the help.
Regards,
Lance
Cliff,
I'm using WF 9.1.1 and attempting to use the RA code you provided. When we build, we get the following error, "'RASession' is not a member of 'Laserfiche.Workflow.Activities'". What am I missing?
Thank You,
Melissa
Melissa,
Insert a clean SDK Script Activity in your test workflow and add this single line of code and try to build it.
Protected Overrides Sub Execute() 'Write your code here. The BoundEntryInfo property will access the entry, RASession will get the Repository Access session Dim mySession As Session = Me.RASession End Sub
If this simple line of code causes an error as well then my guess is that the references in the script activity are corrupt. If you open up the Project Explorer you should see similar entries to this screen shot. Also note the 'Imports' statements at the top of the script. Make sure you have entries similar to the screen shot. (Mine is a 9.2 system so some of the entries will be a bit different)
If the single line of code above builds successfully then carefully review your original script to make sure the syntax is correct.
Thanks Cliff. The references that you mentioned, pointed us in the right direction.
Melissa