web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to pass parameter ...
Power Apps
Unanswered

How to pass parameter to Custom Page

(0) ShareShare
ReportReport
Posted on by 945

Hi guys,

 

In my Model-driven app, I've added a command button to which will open Custom Page. A Javascript has been created, something like this :

function openPageInlineWithContext(selectedItems)
{
 var selectedItem = selectedItems[0];

 if (selectedItem) { 
 let pageInput = {
 pageType: "custom",
 name: "new_accountpage_d32ca",
 entityName: selectedItem.TypeName,
 recordId: selectedItem.Id,
 };
 let navigationOptions = {
 target: 1
 };
 Xrm.Navigation.navigateTo(pageInput, navigationOptions)
 .then(
 function () {
 // Handle success
 }
 ).catch(
 function (error) {
 // Handle error
 }
 );
 }
}

Which in one of the lines is this code -> recordId: selectedItem.Id

It is mentioned that is to "handle" the record id to be passed to Custom Page when it is called.

 

Now in my Custom Page, I have this code in OnStart method :

Set(RecordItem,
 If(IsBlank(Param("recordid")),
 Blank(),
 LookUp(Accounts, Account = GUID(Param("recordid")))
 )
)

But if I tested this Param("recordid") in some Label inside my app, it always empty. May I know how to pass the record from Model-driven View to Custom Page ?

 

The command button in the main grid, when setting the Javascript, I put the parameter to "SelectedControlAllItemReferences"

Axal_0-1651826811782.png

Is this option wrong for me to choose ? or is there anything else that make the record id is not going to my Custom Page ?

 

Thanks

 

 

 

I have the same question (0)
  • Drew Poggemann Profile Picture
    9,287 Most Valuable Professional on at

    Hi @Axal ,

     

    Have you looked at the PowerFX formulas to navigate?  Some are still in preview but might simplify your code.  https://docs.microsoft.com/en-us/power-apps/maker/model-driven-apps/page-powerfx-in-model-app 

     

    Not sure why the parameter is blank based on your code above though on the custom page.

  • Axal Profile Picture
    945 on at

    Hi,

     

    Yes, in some part I have read the document, although to be honest no fully understood all of it. As for the link you gave me, is about Navigate, unfortunately it looks like not what I need, as I really need to pass information from Model-driven first, before some processes happened in Custom Page.

     

    In one of those doc actually there is 1 page interest me - Navigating to and from a custom page in your model-driven app using client API - Power Apps | Microsoft Docs 

    Especially in this section -> Navigating to and from a custom page in your model-driven app using client API - Power Apps | Microsoft Docs

     

    It is talked about :

    1. Create a web resource of type JScript and update the name parameter to be the logical page name. Add the following code to the web resource. (Same as what I already did)

    2. Customize the table ribbon CommandDefinition for OpenRecordItem to call the function above and include the CrmParameter with the value SelectedControlSelectedItemReferences.

     <JavaScriptFunction FunctionName="run" Library="$webresource:cr62c_OpenCustomPage">
     <CrmParameter Value="SelectedControlSelectedItemReferences" />
     </JavaScriptFunction>

    This no 2 is the one that I'm lost. Anyone can help what to do for this step no 2 ?

     

    The next step is again I have done it ->

    3. In the custom page, override the App's OnStart property to use the Param function to get the recordId and lookup record.

     

    Thanks

  • Drew Poggemann Profile Picture
    9,287 Most Valuable Professional on at

    Hi @Axal ,

     

    I just reviewed this video, hopefully this helps...

    https://youtu.be/JYbaDszgCW4

     

  • Axal Profile Picture
    945 on at

    Hi,

    Some updates, turned out there is a typo error with my code in Custom App - OnStart method ->

     

     

    Set(RecordItem,
     If(IsBlank(Param("recordid")),
     Blank(),
     LookUp(Accounts, Account = GUID(Param("recordid")))
     )
    )

     

     

    whereby the "recordid",  supposed to be followed what's typed in Web Resources -> "recordId"

    (the "I" should be uppercase, case sensitive)

     

    Anyway, the Custom App shows something, but it looks still incorrect since it always show the 1st record. Even when I didn't select any row, when I click the button, Custom Page showing Account - 1st record.

     

    Now I'm wondering if this Parameter setup in command grid is the problem ? ->

    Axal_0-1651943958234.png

     

    Anyone can help ?

     

    Thanks

     

     

     

  • Axal Profile Picture
    945 on at

    Hi guys,

     

    Another updates, if I change the Parameter to be SelectedControlSelectedItemRefrence, ->

    Axal_1-1652063593625.png

    My Custom Page able to show the correct record when I select a record in the view grid. However when none selected, the Custom Page is not shown.

     

    I only think, this could be handle without Ribbon Workbench, only I couldn't find where should I correct this. Any suggestion ?

     

    Thanks

     

     

  • andres_b Profile Picture
    30 on at

    Hey @Axal !

     

    I don't know if you're still facing problems, but here's my piece of advice:

     

    1. As a rule of thumb, always use PrimaryControl to pass the correct context from the Model Driven app to the Custom page:

    PrimaryControl.png

     

     

    Then, in your JavaScript, you can get the record's GUID: like this:

     

     

    let itemId = PrimaryControl.data.entity.getId().replace("{", "").replace("}","")

     

     

     

     

    2. To control the visibility of your command, I would also recommend using the Power Fx capabilities if possible:

    PowerFx visibility.png

     

     

    Here's the docs for your reference: Use Power Fx with commands - Power Apps | Microsoft Learn

  • NativeNass_ Profile Picture
    223 on at

    @andres_b  how would this look then in the final JS file?

  • andres_b Profile Picture
    30 on at

    @NativeNass_ ,

    If we use the original's post code, it would look like this:

     

    function openPageInlineWithContext(PrimaryControl)
    {
     let itemId = PrimaryControl.data.entity.getId().replace("{", "").replace("}","")
     let pageInput = {
     pageType: "custom",
     name: "new_accountpage_d32ca",
     recordId: itemId,
     };
     let navigationOptions = {
     target: 1
     };
     Xrm.Navigation.navigateTo(pageInput, navigationOptions)
     .then(
     function () {
     // Handle success
     }
     ).catch(
     function (error) {
     // Handle error
     }
     ); 
    }

     

     

     

     

  • NativeNass_ Profile Picture
    223 on at

    Hi @andres_b  

    Thanks for the quick response.

     

    When I load in this file, the button doesn't even do anything anymore

    NativeNass__0-1697466625054.png

     

    I have been going crazy all day with the same issue.

    FYI; Re: Navigating with context from custom command ba... - Power Platform Community (microsoft.com)

     

    Don't really know what to do anymore

  • andres_b Profile Picture
    30 on at

    @NativeNass_  I forgot to remove the If part of the JS from the original response. See my edited response above and please let me know if it works now!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard