Skip to Content
0

What's the most-efficient way to locate a folder by its path, using BI Platform 4.2 SP4 RESTful SDK?

Feb 21 at 07:20 PM

32

avatar image

What's the most-efficient way to locate a folder by its path, using BI Platform 4.2 SP4 RESTful SDK?

My current approach in PowerShell:
# want to find a folder with the path Foo/Bar/Baz
$path = 'Foo/Bar/Baz'

$Token = 'populated by another REST call'

# create headers
$url="http://server:6405/biprws/v1/cmsquery"
$headers= @{}
$headers.Add("Content-Type","application/xml")
$headers.Add("Accept","application/json")
$headers.Add("x-sap-logontoken",$Token)

# create a query that will find all folders that match name of the last node (Baz)
$lastNode = ($path -split '/')[-1]

$Query = "SELECT * FROM ci_APPobjects,ci_INFOobjects,ci_SYSTEMobjects WHERE si_kind='Folder' AND si_name='$lastNode'"

$payload=`
@"
<attrs 
    xmlns="http://www.sap.com/rws/bip">
    <attr name="query" type="string">$Query</attr>
</attrs>
"@

# POST query to REST (which automatically converts JSON to PsCustomObject[]; return entries node's children; process each child, converting SI_PATH to /path/to/folder; filter objects that don't match $path
(Invoke-RestMethod$url-Method Post -Headers $headers-Body $payload).entries | Select-Object si_id, si_cuid, si_name, si_kind, si_path, `
    @{name = 'Path'; expression = { $p = $_; (( $_.SI_PATH[0].SI_NUM_FOLDERS..1 | % { $p.SI_PATH[0]."SI_FOLDER_NAME$_" } ) -Join "/") + "/" + $_.SI_NAME }}
 | Where-Object { $_.Path -eq $path }

I know that 4.2 SP4 doesn't support the path:// syntax, is there a better way?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Daniel Paulsen
Feb 22 at 12:59 AM
1

Hi Craig,

That's one way to do it without having to make multiple queries and is possibly the most efficient. (don;t use select * though)

Another way could be to use the CMSquery to return the IDs of all folders with the desired name and then query for each ID to see if it has a parent other than "Root Folder" or the root of user folders.

GET /biprws/v1/Folders/<folderID>

you can see if there is a parent by parsing the <link .... rel=up> in the response.

if the response from the "rel=up" link doesn't have a folder name in the path you're looking for, then filter it out and move on to the next id. and start parsing up its path. This method could result in a lot of requests if you have a lot of folders with the same name.

Dan

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Good point on the SELECT *.

It would be *really* helpful if the URI-query functionality, especially the 'PATH://', were to be added to the SDK.

In lieu of that, another option would be to include the path in data set, particularly in a manner that would allow a server-side filter.

0