Crow Canyon Software Forum

Forum Navigation
Please or Register to create posts and topics.

Get folder name from custom action

I have a document library that has folders in it. When a new document is uploaded, I want to grab the [URL Path|FileRef] value and extract the folder name from it. I have the correct regex pattern to do it, but I get an error any time I try to use [URL Path|FileRef] in either a variable or a set column value. I've also tried using it like this: $regextract([URL Path|FileRef],@([^\/]+)(?=\/[^\/]+\/?$)). No joy.

Any hints?

Hi Michael,

We are checking this and will get back soon.

I was able to get this on the form with a Script Action, however, this particular library I'm not going to be using forms so I realized I need to do it in a workflow. I created a WF with a Call Web Service action that returns the data I need:

{
"d": {
"results": [
{
"__metadata": {
"id": "1fdb2053-9ba4-40d4-a71a-01088be29a59",
"uri": "http://sitecollection/NITRO/_api/Web/Lists(guid'd52ca2cd-c9fc-4c8a-a663-5e943eca8af5')/Items(29)",
"etag": "\"1\"",
"type": "SP.Data.TEST_x0020_MOVINGItem"
},
"FieldValuesAsText": {
"__metadata": {
"id": "http://sitecollection/NITRO/_api/Web/Lists(guid'd52ca2cd-c9fc-4c8a-a663-5e943eca8af5')/Items(29)/FieldValuesAsText",
"uri": "http://sitecollection/NITRO/_api/Web/Lists(guid'd52ca2cd-c9fc-4c8a-a663-5e943eca8af5')/Items(29)/FieldValuesAsText",
"type": "SP.FieldStringValues"
},
"FileRef": "/subsite/NITRO/TEST MOVING/FolderName/filename.pdf"
}
}
]
}
}

I can put that into a variable just fine. Then I have another variable, varJSON, that tries to extract that FileRef value: $jsonpath2(RestCallResults##Value,@$.d.results.0.FieldValuesAsText.FileRef).

The logs are showing:

varJSON variable processed. Expression value: $jsonpath2(RestCallResults##Value,@$.d.results.0.FieldValuesAsText.FileRef),
Computed Value:

I've verified that JSON path on an online parser and tried many variations of it with the same result.

I'm at a loss.

Uploaded files:
  • jsonImage.PNG

Hi Michael,

Please use the below syntax to extract the FileRef. After getting the File Ref, please use above regex to extract the folder name from FileRef. We have tried the above regex on our side and it is working fine.

Syntax: $jsonpath2(RestCallResults##Value,@$.d.results[0].FieldValuesAsText.FileRef)

Regex: $regextract([URL Path|FileRef],@([^\/]+)(?=\/[^\/]+\/?$))

 

Thank you. The jsonpath2 statement worked. Just needed the square brackets. I also got the regex working. I thought $regextract would "pull out" the string it matched to put it in a column or variable. Instead it deletes it. So I used $regexreplace with a pattern that matched everything but the text I wanted and replaced it with nothing. Now I have just the folder name from the library.