How to pass an object from a model app driven app to a custom page?

According to the current documentation, we can pass a dataverse record as a parameter. This is still very beneficial for some scenarios. But what if we want to pass a set of parameters without using an existing record.


After several attempts, I managed to pass an object containing some properties from the model driven app to the custom page using the navigateTo method. The next video illustrates this scenario. Indeed, the idea is to pass an object which contains two properties of type text from the MDA to the Custom Page using the navigateTo method.

As you can see, I used the recordId parameter to pass my JSON object. According to the documentation for the navigateTo method, the recordId parameter is optional and expects to be passed a GUID parameter.
Fortunately for us, Microsoft does not check if we pass a GUID or not, the API expects a string. Using this behavior, we can pass a JSON using this parameter.

var pageInput = {
pageType: "custom",
name: "mea_home_809de",
recordId:JSON.stringify({prop1: "Hello,", prop2: " World !"})
};
Xrm.Navigation.navigateTo(pageInput).then(
function success() {
// Run code on success
},
function error() {
// Handle errors
}
);

In my opinion, this is still a bug, it is better to add validation for this type of parameter and give us the possibility to pass an object using a “data” parameter as for a normal webresource.

as indicated in the documentation of the navigateTo method for the “custom” type, we can retrieve the recordId parameter using the Param(“recordId”) function. As we have passed a JSON instead of a GUID, we will have to parse this JSON to extract the values of the different properties.

Set(inputParameters,JSON(Param("recordId")));
Set(props, Match(inputParameters, "\""prop1"":""(?<prop1>[^""]*)"",""prop2"":""(?<prop2>[^""]*)"))

Then I can use the values extracted from the JSON. In my case, I used a simple concatenation:

Concatenate("Props from MDA 🤓", props.prop1, " ", props.prop2)

Hope it helps…

3 thoughts on “How to pass an object from a model app driven app to a custom page?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s