cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
MikeInCairns
Level: Powered On

Compose Action in lieu of Variables

 

I am using a SharePoint list with a Flow.

 

For the current item, I want to read one field, subtract 10 from the field, then update another field in the list.

 

I don't see any ability to use a variable in Flow, so can I use a Compose Action for this?

 

Something like:

 

1. Trigger: When new item is created then

2. Compose Action: ContractNo=[ID]-10 then

3. Update Action: NewField=ContractNo Output

 

Would this work?  Any better ideas?

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Compose Action in lieu of Variables

Hi @MikeInCairns,

 

What is your current situation?

Could you please share information about the ID range?

If the ID range is within 10000, then we could somehow workaround the number format with the substring () function in Workflow definition language:

Substring('string',Start Index, length)

For example, we would keep the 0xxx format, the following should work:

"@concat('ABC-',substring(string(add(sub(float(triggerbody()?['Title']),10),10000)),1,4))"

Reference:

83.PNG

84.PNG

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

10 REPLIES 10
Community Support Team
Community Support Team

Re: Compose Action in lieu of Variables

Hi @MikeInCairns,

 

Yes, that would work.

 

I have a few concern about the ID you used here. The ID should already be used as an system field, which can't be set to an available item field, so could you please explain a bit for this field?

In addition, what is the New Field (ContractNo) and th ID field type?

To be able to subtract, the field type need to be Number.

If for string field, we could take use of the Float() or int () function to convert the number into the corresponding type.

For example, the following flow would convert the title field from string into Float, then subtract 10 from the number, update the ContactNo with the compose outputs,

Formula used in Compose:

"@sub(float(triggerbody()?['Title']),10)"

Function reference

74.PNG

 

See the results:

75.PNG

If you need any further assistance on this, please post back.

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
MikeInCairns
Level: Powered On

Re: Compose Action in lieu of Variables

Thought I should provide clearer details about what I am trying to achieve.  I have a SharePoint Designer workflow that does what I want, but I would rather use the new Flow if possible.

 

I have a SharePoint list.  Every item in the list is assigned an item ID by SharePoint.  I also have another column (lets call it ContractNo).  The ContractNo field must be calculated from the ID field, but this is not allowed in SharePoint so I need to do it using workflow.

 

I need to produce a ContractNo in the format ABC-0100, where ABC is static text and 0100 is the ID number minus 10.

 

So for an ID=30 the calculated ContractNo field need to be ABC-0020.

 

It is so easy in Designer because you can use Variables and also functions like TEXT(x,"0000").

Super User
Super User

Re: Compose Action in lieu of Variables

we cannot create custom variables in Flow. Not yet. I also need it, and yes we could do it in SPD 🙂 

 

Cheers

 

Serge Luca

SharePoint MVP

www.shareql.com

 

MikeInCairns
Level: Powered On

Re: Compose Action in lieu of Variables

Thankyou Serge, but your post does not answer the question.

 

I know we cannot use variables in Flow...hence the question...can we do something with Compose Action instead?  I believe Micheal has suggested we can.  So i am hoping someone can post more detail.

Super User
Super User

Re: Compose Action in lieu of Variables

something like this ?  "@Concat('ABC-',sub(float(triggerbody()?['ID']),10))"  ; that works on a SharePoint list (I've tested it) but indeed the issue is formatting the string  in the format you want and the Logic Apps Workflow Definition Language doesn't provide that as far as I know.

 I would rely on the Custom API (like an Azure function) to achieve it. But that requires coding.

Community Support Team
Community Support Team

Re: Compose Action in lieu of Variables

Hi @MikeInCairns,

 

What is your current situation?

Could you please share information about the ID range?

If the ID range is within 10000, then we could somehow workaround the number format with the substring () function in Workflow definition language:

Substring('string',Start Index, length)

For example, we would keep the 0xxx format, the following should work:

"@concat('ABC-',substring(string(add(sub(float(triggerbody()?['Title']),10),10000)),1,4))"

Reference:

83.PNG

84.PNG

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

MikeInCairns
Level: Powered On

Re: Compose Action in lieu of Variables

Thanks Michael

That looks perfect - I will try it in the next few days.  We will have far less than 10,000 items in the list so the xxxx formatting should be OK.

MikeInCairns
Level: Powered On

Re: Compose Action in lieu of Variables

This is BLOODY BRILLIANT!!!  Thank you very much Michael for your persistence with me to get this working.  This has really open up my eyes to the power of Workflow Definition Language.  I am quite good with XML, VBA and DAX, but I obviously now have another language I need to learn!!  

 

So apparently we dont need Variables if we understand how to use the Compose Action.  I look forward to learning more.  Any good resources you could reccoment to a newbie?

 

Thanks Again

Mike

ArtSys
Level: Power Up

Re: Compose Action in lieu of Variables

For anyone else reading this in August or thereafter, variables are now supported in Microsoft Flow. 

 

There are four actions - initialize variable, increment variable, decrement variable and set variable. 

 

The Initialize action needs to happen after your trigger in the beginning of the flow, and there you can specify the type (Bool, Int, Float, String, Obj, Array). 

 

The set variable can then be used to modify a string variable in a switch case or whatever else you want. 

jessicaf31
Level: Powered On

Re: Compose Action in lieu of Variables

Hello ! Is this possible then to use a variable for a list address?!

I have a first list with a selection of 20 business units (yes/no radio button).

If the user selects "yes" for one(or more) business unit(s), then the business unit list is updated...can you help me ?! Thanks!

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Users Online
Currently online: 215 members 5,372 guests
Please welcome our newest community members: