CRM Crate

How to open an URL in Dynamics 365 form using JavaScript

We will learn to open an URL in Dynamics 365 form using JavaScript. Before we start, make sure to subscribe to CRM Crate so that you stay up-to-date in field of Dynamics 365.

See the source image

Using openURL Client API Reference to open the web URL –

We will use the openURL client API to open the web URL from an entity form.

Xrm.Navigation.openUrl(url,openUrlOptions)

Opens a URL, including file URLs. This method is especially helpful for mobile clients to open a URL in a browser outside of shim.

Below are the details of parameters required by the client API.

NameTypeRequiredDescription
urlStringYesURL to open.
openUrlOptionsObjectNoOptions to open the URL.The object contains the following values:
– height: (Optional) Number. Height of the window to display the resultant page in pixels.
– width: (Optional) Number. Width of the window to display the resultant page in pixels.

JavaScript snippet code for opening the web URL –

The below JavaScript code has been triggered during the OnChange event of form’s field.

//CRM Crate - JavaScript Snippet
function CallMethod (executionContext) {

//Retrieving Field Values.
var URL = Xrm.Page.getAttribute("cc_url").getValue();
var LaunchURL = Xrm.Page.getAttribute("cc_input").getValue();

//Creating An Object For Storing Window Height & Width
 var openUrlOptions = {
        height: 800,
        width: 800
    };

if(LaunchURL == true )
{

//Using openURL Client API To Open The Website.
Xrm.Navigation.openUrl(URL,openUrlOptions)
Xrm.Page.getAttribute("cc_input").setValue(false);
}
}

Validate the output in Dynamics 365 –

Once the above code has been configured and deployed, verify whether the web URL gets open in a new browser tab as expected.

Thus we learned to open an URL from Dynamics 365 form using JavaScript.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
error: CRM Crate Security Engine - Disabled Right Click & Selection!

Congratulations!

Well Done,
Welcome to CRM Crate

Stay tuned with us and get all latest updates and learning in Microsoft CRM and related techonologes.