
I created the button on Ribbon Workbench and associated it to a command, which is related to a JS function (emtpy, for now).
I need to implement this JS function to set the visibility of a button.
It's not clear to me how should I pass the execution context to the function and how should I refer to the button (should I use its logical name as if it was a field?)
I saw the following example related to a script which was associated to a form:
formContext.getControl("logical_name_of_the_button?").setVisible(false);
...but in that case the formContext was retrieved through the execution context, which is a parameter passed by default to the function while setting the web resource from crm configuration (by selecting "pass the execution context as first parameter"), is it correct?
If it's correct, how should I pass the context in this case instead?
Hi,
You need to create a enable rule and pass the primarycontrol as CRMParameter which is nothing but the form context. You will not get executioncontext - just directly the formcontext.
Below is a sample :
Code can be something like this:
function RibbonRule(formContext)
{
var recordId = formContext.data.entity.getId().replace("{", "").replace("}", "");
var globalContext = Xrm.Utility.getGlobalContext();
var serverUrl = globalContext.getClientUrl();
var url = Xrm.Page.context.getClientUrl() "/api/data/v9.1/ps_configurationsettings?$filter=ps_key eq 'key'";
var reqCS = new XMLHttpRequest();
reqCS.open("GET", url, false);
reqCS.setRequestHeader("Accept", "application/json");
reqCS.setRequestHeader("Content-Type", "application/json; charset=utf-8");
reqCS.send();
if (reqCS.readyState == 4) {
if (reqCS.status == 200) {
var data = JSON.parse(reqCS.response);
if (data != null && data.value.length > 0) {
return false;
}
}
else {
return true;
}
}
return true;
}