Skip to main content

Notifications

Power Automate - Building Flows
Answered

SOLVED - Split at ONCE several strings or when an item is created in multiple records on a new Sharepoint List considering empty values.

(0) ShareShare
ReportReport
Posted on by 23

Hello Community!

 

I am trying to build a flow in Power Automate to create new records from "List1" to "List2" in SharePoint. I have a column called "Pallet Tag", and this column can have multiple pallets - separates by "/" -, empty values or just one pallet recorded.

 

Visually, I want to following:

Untitled design (7).png

 When I run the flow, I have this message: 

"Unable to process template language expressions for action 'Condition' at line '0' and column '0': 'The template language function 'contains' expects its first argument 'collection' to be a dictionary (object), an array or a string. The provided value is of type 'Null'.'."

 

Untitled design (4).png

The flow looks like:

 

 

3.png

5.png6.png7.png

 

Untitled design (8).png

Thank you very much in advance,

Danie

 

UPDATE:

First of all, thank you very much @DJ_Jamba and @eliotcole. I used your ideas to solve the issue. I had two problems: first, getting all items and copying them with a new format to a new list, and second, copying each new item every time it was created. It was difficult for me, but now I have two different flows (one inactive to copy all the items just in the beginning, and then the second for real-time copy). I didn't know the split function was different for both, but finally, I have both formulas.

I am attaching them here in case someone needs this solution.

Cheers, Danie

 

11.png12.png

  • Suggested answer
    takolota1 Profile Picture
    takolota1 4,785 on at
    SOLVED - Split at ONCE several strings or when an item is created in multiple records on a new Sharepoint List considering empty values.
    There is a way to split a column on delimiters to multiple records using only 6 actions & it will work for any number of records. And it will handle null / blank values in the split column.
    https://community.powerplatform.com/galleries/gallery-posts/?postid=b4b53bc0-0e9a-ef11-8a69-6045bdee0f9b
  • eliotcole Profile Picture
    eliotcole 4,196 on at
    Re: Split string in multiple records on a new Sharepoint List

    Hi, @ddl3 ... I have a feeling that you may be better off using a few Select actions, here, to get this done without any loops.

     

    I haven't built this, so I'm just spitballing.

     

    You could perform a Select action and name it 'SelectList2Items' which has this in the Map field:

    addProperty(
    	addProperty(
    		addProperty(
    			item(), 
    			'pallettesArr', 
    			split(
    				replace(
    					trim(item()?['LotPallet_x0023_']), 
    					' ', 
    					''
    				), 
    				'/'
    			)
    		),
    		'pallettesCountInt', 
    		length(
    			split(
    				replace(
    					trim(item()?['LotPallet_x0023_']), 
    					' ', 
    					''
    				), 
    				'/'
    			)
    		)
    	),
    	'hasPallettes', 
    	greater(
    		length(
    			split(
    				replace(
    					trim(item()?['LotPallet_x0023_']), 
    					' ', 
    					''
    				), 
    				'/'
    			)
    		), 
    		0
    	)
    )

    This will give you the following values on top of everything else:

    1. pallettesArr - An array of every pallette they listed
    2. pallettesCountInt - A count of the amount of pallettes they listed
    3. hasPallettes - Whether or not they have any pallettes to handle

    Then if create an 'Apply to each' or 'For each' named 'ForEveryList2Item' on the newly made 'SelectList2Items' you can make the first action a condition based upon:

    Left Condition Right
    @{items('ForEveryList2Item')?['hasPallettes']}
    is equal to
    @true

    Then for each of the branches you can do the following:

    If yes

    Create an item in List 2 using another 'Apply to each'/'For each' action based on this value:

    @{items('ForEveryList2Item')?['pallettesArr']}
    If no

    Make a single item in List 2.

    You can hack around the empty fields either by inserting the following:

    @null

    ... or you can use references to add the item using the 'Update item' hack I listed here, but just apply it to the 'Creat item' action instead. I'm sure it'll be fine.

     

    I'm a bit too tired to actually *do* this for you, but it should be sound. 🙂

  • Verified answer
    DJ_Jamba Profile Picture
    DJ_Jamba 2,327 on at
    Re: Split string in multiple records on a new Sharepoint List

    Hi @ddl3 

     

    It looks like it's failing on the User2 record because there is no Pallet Tag and you can't split a null.
    So based on your example:

    DJ_Jamba_0-1713390857602.png

    When you are looping through List 1, your condition would be:

    If Pallet Tag column is equal to null

    Create item
    action (in the Yes block of the condition)
    and only supply:

    Record ID field
    Date field
    Created by Name field


    Else (in the No block of the condition)
    Another Apply to each action based on the split function against the Pallet Tag field.
    Add a Create item action inside the 2nd loop which populates Record ID, Date, Created by Name and Pallet Tag from the first Apply to each loop
    And Flow - Pallet Tag field is populated from the 2nd Apply to each loop

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,567

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,907

Leaderboard