cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sipark09
Regular Visitor

Calling a value from user provided variable in SharePoint

Hello,

 

I am wondering with SharePoint, if it's possible to find it's unique ID that is randomly assigned to it. 

For example, the first item in this list has a randomly assigned unique ID, 1. 

Would a user of the chatbot be able to call the ID number by the URL and how would you do that in PVA/creating a flow in Power Automate. 

sipark09_1-1656346093357.png

 

Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions

OK, @sipark09, I'm going to have to assume a fair bit here, but I'll mark my assumptions.

 

Plus, before I get in to it, it's important that you understand that you can't control what they put into that field, so you realistically need to prepare for all eventualities. This is the position that you're in with regard to gathering this data.

 

Firstly, get that image into your original question, as it'll assist anyone who comes to help you with context for what you're talking about.

 

My first assumption is:

I am assuming that the PVA is asking them to provide a link to a SharePoint item.

 

If that's the case, then there are a few different links to SharePoint items:

  1. Copying/Pasting the link from the address bar
    https://YOUR_DOMAIN.sharepoint.com/sites/YOUR_SITE/Lists/YOUR_LIST/DispForm.aspx?ID=THE_ITEM_ID
  2. Using the menu to provide a link to the item
    https://YOUR_DOMAIN.sharepoint.com/:li:/s/YOUR_SITE/RANDOM_GUID?e=UNIMPORTANT_TRACKING
  3. Using the '{Link}' column that's offered in places like Power Automate
    https://YOUR_DOMAIN.sharepoint.com/sites/YOUR_SITE/_layouts/15/listform.aspx?PageType=PAGE_TYPE_ID&ListId=YOUR_LIST_ID&ID=THE_ITEM_ID&ContentTypeID=CONTENT_TYPE_ID

And, the first one is actually the result of following the link provided by the second link type!

 

So it all depends what URL they're presenting to the PVA, even if you ask them to provide a certain one, you can't be sure (unless you have verification/validation/whatever on the question) it'll match.

 

Now, each of those actually can be used to identify the item.

 

Link Types 1 & 3

These are essentially the same thing, so you should use the same process.

 

My second assumption is that the URL field there in the PVA is a trigger value, which one can call with either of these expressions:

triggerBody()['text']

If there are other fields defined it may have a different reference, like

triggerBody()['text_3']

I will use the first one here, just be sure that you refer to the correct field in yours.

 

(you have since confirmed this assumption, but the usefulness is still there)

 

You get the ID by splitting the URL_REF, in this case triggerBody()['text'], however you can purely look at everything after the question mark (the query) by using the function:

uriQuery(triggerBody()['text'])

 

Now you need to split on ID=, except you don't know what else will be inside that uriQuery() value, which could include other parameters that end with ID=. So you need to include a condition in there to check.

 

The full expression looks something like this:

int(
    if(
        startsWith(
            uriQuery(triggerBody()['text']), 
            '?ID='
        ), 
        split(
            split(
                uriQuery(triggerBody()['text']), 
                '?ID='
            )[1], 
            '&'
        )[0],
        split(
            split(
                uriQuery(triggerBody()['text']), 
                '&ID='
            )[1], 
            '&'
        )[0]
    )
)

This is broken down in this spoiler:

Spoiler
  1. Firstly the if() function checks if the ID value is the first query parameter by using startsWith() to check if the string begins with the text ?ID=.
    1. If true, then it:
      1. Runs split() on ?ID= and takes the second entry [1] from the array,
      2. Then it runs split() on the ampersand symbol in case there are other values in there, and takes the first entry of that array [0].
    2. If false,
      1. Runs split() on &ID= and takes the second entry [1] from the array,
      2. Then it runs split() on the ampersand symbol in case there are other values in there, and takes the first entry of that array [0].
  2. After the if() function has run its course, it then ensures that the number is presented as an integer using the int() function.

 

Link Type 2

If the link is of type #2, then you need to use my solution here:

https://powerusers.microsoft.com/t5/Building-Flows/Move-my-list-hyperlink-from-SharePoint-site-to-an...

It's a bit more advanced, so you need to ensure that you're at home with everything there, because it's using some quite specific functions.

View solution in original post

4 REPLIES 4
eliotcole
Super User
Super User

Hi, @sipark09, have you tried to actually make a flow, yet? ( not said sarcastically! 😉 )

 

The first thing that you see when playing around with SharePoint lists will be the ID field.

 

Just do some playing around and testing, and you'll find that you can do so much! Including filtering on the trigger!

Hello @eliotcole 

 

Below is what I've been trying to do.

But obviously the error comes from the output in the ID field not being an integer. Currently it's the URL. 

So I was wondering how i can call the ID number from the user input which would be the URL. 

sipark09_0-1656347074534.png

 

Thanks

 

@eliotcole 

 

I'm also using the PVA Trigger (when PVA/chatbot calls a flow) so the SharePoint triggers are not in play here.

OK, @sipark09, I'm going to have to assume a fair bit here, but I'll mark my assumptions.

 

Plus, before I get in to it, it's important that you understand that you can't control what they put into that field, so you realistically need to prepare for all eventualities. This is the position that you're in with regard to gathering this data.

 

Firstly, get that image into your original question, as it'll assist anyone who comes to help you with context for what you're talking about.

 

My first assumption is:

I am assuming that the PVA is asking them to provide a link to a SharePoint item.

 

If that's the case, then there are a few different links to SharePoint items:

  1. Copying/Pasting the link from the address bar
    https://YOUR_DOMAIN.sharepoint.com/sites/YOUR_SITE/Lists/YOUR_LIST/DispForm.aspx?ID=THE_ITEM_ID
  2. Using the menu to provide a link to the item
    https://YOUR_DOMAIN.sharepoint.com/:li:/s/YOUR_SITE/RANDOM_GUID?e=UNIMPORTANT_TRACKING
  3. Using the '{Link}' column that's offered in places like Power Automate
    https://YOUR_DOMAIN.sharepoint.com/sites/YOUR_SITE/_layouts/15/listform.aspx?PageType=PAGE_TYPE_ID&ListId=YOUR_LIST_ID&ID=THE_ITEM_ID&ContentTypeID=CONTENT_TYPE_ID

And, the first one is actually the result of following the link provided by the second link type!

 

So it all depends what URL they're presenting to the PVA, even if you ask them to provide a certain one, you can't be sure (unless you have verification/validation/whatever on the question) it'll match.

 

Now, each of those actually can be used to identify the item.

 

Link Types 1 & 3

These are essentially the same thing, so you should use the same process.

 

My second assumption is that the URL field there in the PVA is a trigger value, which one can call with either of these expressions:

triggerBody()['text']

If there are other fields defined it may have a different reference, like

triggerBody()['text_3']

I will use the first one here, just be sure that you refer to the correct field in yours.

 

(you have since confirmed this assumption, but the usefulness is still there)

 

You get the ID by splitting the URL_REF, in this case triggerBody()['text'], however you can purely look at everything after the question mark (the query) by using the function:

uriQuery(triggerBody()['text'])

 

Now you need to split on ID=, except you don't know what else will be inside that uriQuery() value, which could include other parameters that end with ID=. So you need to include a condition in there to check.

 

The full expression looks something like this:

int(
    if(
        startsWith(
            uriQuery(triggerBody()['text']), 
            '?ID='
        ), 
        split(
            split(
                uriQuery(triggerBody()['text']), 
                '?ID='
            )[1], 
            '&'
        )[0],
        split(
            split(
                uriQuery(triggerBody()['text']), 
                '&ID='
            )[1], 
            '&'
        )[0]
    )
)

This is broken down in this spoiler:

Spoiler
  1. Firstly the if() function checks if the ID value is the first query parameter by using startsWith() to check if the string begins with the text ?ID=.
    1. If true, then it:
      1. Runs split() on ?ID= and takes the second entry [1] from the array,
      2. Then it runs split() on the ampersand symbol in case there are other values in there, and takes the first entry of that array [0].
    2. If false,
      1. Runs split() on &ID= and takes the second entry [1] from the array,
      2. Then it runs split() on the ampersand symbol in case there are other values in there, and takes the first entry of that array [0].
  2. After the if() function has run its course, it then ensures that the number is presented as an integer using the int() function.

 

Link Type 2

If the link is of type #2, then you need to use my solution here:

https://powerusers.microsoft.com/t5/Building-Flows/Move-my-list-hyperlink-from-SharePoint-site-to-an...

It's a bit more advanced, so you need to ensure that you're at home with everything there, because it's using some quite specific functions.

Helpful resources

Announcements
 WHAT’S NEXT AT MICROSOFT IGNITE 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Register for a Free Workshop.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Users online (1,386)