Hello everyone,
I created a button using the RibbonWorkbench tool on the Work order table.
I would like to show/hide the button based on the below simple criteria:
If the work order status = "Scheduled" and the Work Order Type = "Visit" and the Primary Incident Type = "Visit" the button should be visible else it will not be visible on the ribbon.
It seems that to achieve this requirement, I need to inject a JS as a CustomRule and JS action to the command for this button as the setup that I did below:
The JS code that I did is the below is working and returning data as expected as I have tested it in OnLoad event of the form as below:
function getFormatedName(query){ if(query.getValue()!== null)return query.getValue()[0].name.toLowerCase(); else return null } function RibbonShowHideButton(executionContext) { debugger; let formContext = executionContext.getFormContext(); let status = formContext.getAttribute("msdyn_systemstatus").getValue(); console.log(status); if(status === "690970001" || 690970001){ let work_type = formContext.getAttribute("msdyn_workordertype"); console.log(work_type); let incident_type = formContext.getAttribute("msdyn_primaryincidenttype"); console.log(incident_type); let agreement = formContext.getAttribute("msdyn_agreement"); let service =formContext.getAttribute("msdyn_serviceaccount").getValue(); let flag = false; if(flag === false){ if(getFormatedName(work_type) === "visit" && getFormatedName(incident_type) === "visit"){ console.log("COndition entered"); return true; } } } } function refreshRibbon(executionContext){ var formContext = executionContext.getFormContext(); formContext.ui.refreshRibbon(); }
However, after I published and opened a record that satisfies the above condition, the button is always hidden and not visible at all.
I tried to debug the button by using the command checker but it does not show the details needed.
Could you please advise why the button is always hidden and not showing?
Would highly appreciate it if you can provide an example.
Thank you,
EBMRay