Question

I need to make a HTML web-resource where I can add a button on it. The button should open a Dialog, I have already made the HTML page and add it to the web-resources in CRM11. But now I need to pass parameters on the click event so we can call the dialog. The dialog gets triggered by the java script code in it. I don't know how to pass these parameters from HTML to javascript.

I need to add these parameters to the javascript code:

HTML

<HTML><HEAD><TITLE>Untitled Page</TITLE>
<META charset=utf-8></HEAD>
<BODY contentEditable=true>
<SCRIPT src="ClientGlobalContext.js.aspx"></SCRIPT>

<SCRIPT type=text/javascript src="rd_/javascripts/LaunchModalDialog.js"></SCRIPT>

<STYLE type=text/css>
    #Button1
    {
        width: 200px;
    }
</STYLE>

<P><INPUT id=Button1 onclick=LaunchModalDialog() value=button type=button>       </P></BODY>    </HTML>

Javascript

function LaunchModalDialog(dialogId, typeName, recordId)
{
var serverUrl = Xrm.Page.context.getServerUrl();
recordId = recordId.replace("{", "");
recordId = recordId.replace("}", "");

dialogId = dialogId.replace("{", "");
dialogId = dialogId.replace("}", "");

// Load Modal
var serverUri = serverUrl + '/cs/dialog/rundialog.aspx';
var myPath = serverUri + '?DialogId=%7b' + dialogId.toUpperCase()  +'%7d&EntityName=' + typeName+'&ObjectId=%7b' +recordId+'%7d';

// First item from selected record
window.showModalDialog(myPath);

// Reload form
window.location.reload(true);
} 
Was it helpful?

Solution

For that you write the values for the parameter in the HTML as

onclick="LaunchModalDialog(firstParam, secondParam, thirdParam)"

This way, when it would trigger, it would pass on the values.

It can be anything, integer, string etc. What so ever you want to send to the function.

Also, please note that the values for attributes must be qouted

<input id="Button1" 
 onclick="LaunchModalDialog(firstParam, secondParam, thirdParam)" 
 value="button" type="button" /> 

You have only 3 parameters, that's why I have included only 3, you can add more or less depending on the nature and type of function you're using.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top