Add a gallery in PowerApps, then search for "Power" and the "Power Platform for Admins" connector will appear.
![Power Plateform]()
Next, you can set the items to collect the environments using this function.
PowerPlatformforAdmins.GetAdminEnvironment().value
More than 250 environments!
To retrieve more than 250 environments, it is necessary to obtain a token that allows access to the next list of environments through pagination. In this case, you need to add the following two parameters:
PowerPlatformforAdmins.GetAdminEnvironment({'$skiptoken:','$paginationid:'})
Retrieve the skipToken
Retrieve the first page of the environments.
ClearCollect( coListENV_PAGE1 ; PowerPlatformforAdmins.GetAdminEnvironment( ) );;
_colistEnv_PAGE1.nextLink
![Azure]()
Set a skipToken variable using the following formula.
Set(SkipToken; Replace(Replace(Replace(varPAGE1_NextLink;1; Find("skiptoken=";varPAGE1_NextLink;1)+9;"");Find("&%24paginationId=";Replace(varPAGE1_NextLink;1; Find("skiptoken=";varPAGE1_NextLink;1)+9;"");1);Len(varPAGE1_NextLink);"");Find("%3d";SkipToken;1);3;"="))
with the variable `varPAGE1_NextLink`.
_colistEnv_PAGE1.nextLink
Retrieve the pagination ID
Set the variable `PaginationId`.
Set(PaginationId;Replace(varPAGE1_NextLink;1;Find("&%24paginationId=";varPAGE1_NextLink;1)+16;"")
Collect the `environments` variable, which will contain the details of the environments.
Collect(Environments;PowerPlatformforAdmins.GetAdminEnvironment({'$skiptoken':SkipToken,'$paginationid':PaginationId}).Value)
![Detail]()
Example
In this example, we have added a button labeled "Get All Env."
// Collect the first list of environments into the 'Environments' variable
ClearCollect( Environments; PowerPlatformforAdmins.GetAdminEnvironment().value );
// Collect the value and nextLink into the 'coListENV_PAGE1' variable
ClearCollect( coListENV_PAGE1; PowerPlatformforAdmins.GetAdminEnvironment() );
// Set 'varPAGE1_NextLink' to select the next link
Set( varPAGE1_NextLink; First(coListENV_PAGE1[@nextLink]).nextLink );
// Clean the 'varPAGE1_NextLink' variable to get the token into the 'SkipToken' variable
Set( SkipToken;
Replace(
Replace(
varPAGE1_NextLink;
1;
Find( "skiptoken="; varPAGE1_NextLink; 1 ) + 9;
""
);
Find( "&%24paginationId="; Replace( varPAGE1_NextLink; 1; Find( "skiptoken="; varPAGE1_NextLink; 1 ) + 9; "" ); 1 );
Len(varPAGE1_NextLink);
""
)
);
// Check if 'SkipToken' exists (the existence of the skip token indicates there is a new page of data to retrieve)
If(
!IsBlank(SkipToken);
Collect(
Environments;
PowerPlatformforAdmins.GetAdminEnvironment(
{
'$skiptoken': Replace( SkipToken; Find( "%3d"; SkipToken; 1 ); 3; "=" );
'$paginationid': Replace( varPAGE1_NextLink; 1; Find( "&%24paginationId="; varPAGE1_NextLink; 1 ) + 16; "" )
}
).value
)
);
// Retrieve the second link and store the next link in 'varPAGE1_NextLink'
Set(
varPAGE1_NextLink;
PowerPlatformforAdmins.GetAdminEnvironment(
{
'$skiptoken': Replace( SkipToken; Find( "%3d"; SkipToken; 1 ); 3; "=" );
'$paginationid': Replace( varPAGE1_NextLink; 1; Find( "&%24paginationId="; varPAGE1_NextLink; 1 ) + 16; "" )
}
).nextLink
);
// If 'varPAGE1_NextLink' is not empty, reset 'SkipToken'; otherwise, redefine 'SkipToken'
If(
IsBlank(varPAGE1_NextLink);
Set( SkipToken; Blank() );
Set( SkipToken;
Replace(
Replace(
varPAGE1_NextLink;
1;
Find( "skiptoken="; varPAGE1_NextLink; 1 ) + 9;
""
);
Find( "&%24paginationId="; Replace( varPAGE1_NextLink; 1; Find( "skiptoken="; varPAGE1_NextLink; 1 ) + 9; "" ); 1 );
Len(varPAGE1_NextLink);
""
)
)
)
Explanation
- Collecting Environments: The code starts by clearing and collecting the first list of environments from the PowerPlatformforAdmins.GetAdminEnvironment() function into the Environments variable.
- Next Link Collection: It then collects the response, including the next link, into the coListENV_PAGE1 variable.
- Next Link Setup: The varPAGE1_NextLink variable is set to the first next link from the collected data.
- Skip Token Extraction: The code processes varPAGE1_NextLink to extract the SkipToken, which is necessary for pagination.
- Conditional Collection: It checks if the SkipToken is not blank, indicating that there are more pages of data to retrieve, and collects additional environments accordingly.
- Next Link Retrieval: The code sets varPAGE1_NextLink again based on the new pagination parameters.
- Resetting or Defining SkipToken: Finally, it checks if varPAGE1_NextLink is blank. If it is, it resets the SkipToken; otherwise, it redefines it.
This structure allows you to effectively manage and paginate through a large dataset of environments using the Power Platform Admin connector in PowerApps.
Add a gallery, and in the Items property, add the following code.
SortByColumns(AddColumns(Environments, "DisplayName", properties.displayName), "DisplayName")
Explanation
- AddColumns: This function adds a new column named DisplayName to the Environments collection, populating it with the values from properties.displayName.
- SortByColumns: This function sorts the resulting collection by the DisplayName column.
This will allow the gallery to display the environments sorted by their display names.