Hi,
I've managed to cobble together my first javascript ever (yay!) and it works fine. This is how it looks:
ObjectivesSubGridFilterExecution = function (executionContext, teamGuid, gridName) {
// some of working code
}
In my configuration, I call it like this:
Now, I'd like to follow best practice and use namespaces. There are lots of examples of various ways of doing this but none that I can get to work. Let's say I'd like to create a namespace "geoproject" so I configure my event to call geoproject.ObjectivesSubGridFilterExecution (and more functions that will be added to the .js file). All my attempts so far result in a dialog box informing me that it can't find the function geoproject.ObjectivesSubGridFilterExecution
What's the syntax? Any help much appreciated!
Hi,
That did the trick, thanks! I had failed to prefix the function name with "Sdk.". I added it to both my functions, and called the second from within the first prefixed by "Sdk.".
I assume I could replace "Sdk" with a namespace name of my choice?
Cheers!
Hi @Rydman ,
Could you try this:
var Sdk = window.Sdk || {};
Sdk.SubGridFilterExecution = function (executionContext, team) {
var teamGuid;
var gridNo;
// The GUIDS mapped here can be found in the cr047_GeothermalProjectTeam table, column cr047_GeothermalProjectTeamId
switch(team) {
case "resource":
teamGuid = "22db93c2-3bc2-ec11-983f-6045bd948406";
gridNo = "1"
break;
case "bd":
teamGuid = "23db93c2-3bc2-ec11-983f-6045bd948406";
gridNo = "2"
break;
case "project":
teamGuid = "24db93c2-3bc2-ec11-983f-6045bd948406";
gridNo = "3"
break;
case "all":
teamGuid = "d2439bd2-b1c7-ec11-a7b6-000d3aad0e38";
gridNo = "4"
break;
default:
}
var formContext = executionContext.getFormContext();
SubGridFilter(formContext, teamGuid, "Subgrid_objectives_" + gridNo, "cr047_objective");
SubGridFilter(formContext, teamGuid, "Subgrid_decisions_" + gridNo, "cr047_decision");
SubGridFilter(formContext, teamGuid, "Subgrid_deliverables_" + gridNo, "cr047_deliverable");
SubGridFilter(formContext, teamGuid, "Subgrid_tasks_" + gridNo, "cr047_task");
};
SubGridFilter = function (formContext, teamGuid, gridName, entityName) {
var phase = formContext.getAttribute("cr047_phase").getValue();
formContext.ui.setFormNotification("team: " + teamGuid + " phase:" + phase + " gridname:" + gridName + " entity:" + entityName, "INFO", "_myUniqueId");
var FetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='" + entityName + "'>" +
"<attribute name='cr047_project' />" +
"<filter type='and'>" +
"<condition attribute='cr047_phase' operator='eq' value='" + phase + "' />" +
"<condition attribute='cr047_team' operator='eq' value='" + teamGuid + "' />" +
"</filter>" +
"</entity>" +
"</fetch>";
var gridContext = formContext.getControl(gridName);
gridContext.setFilterXml(FetchXml);
formContext.getControl(gridName).refresh();
};
Best Regards,
Wearsky
Hi,
Here goes (the working script, not featuring any of my attempts to use namespaces):
SubGridFilterExecution = function (executionContext, team) {
var teamGuid;
var gridNo;
// The GUIDS mapped here can be found in the cr047_GeothermalProjectTeam table, column cr047_GeothermalProjectTeamId
switch(team) {
case "resource":
teamGuid = "22db93c2-3bc2-ec11-983f-6045bd948406";
gridNo = "1"
break;
case "bd":
teamGuid = "23db93c2-3bc2-ec11-983f-6045bd948406";
gridNo = "2"
break;
case "project":
teamGuid = "24db93c2-3bc2-ec11-983f-6045bd948406";
gridNo = "3"
break;
case "all":
teamGuid = "d2439bd2-b1c7-ec11-a7b6-000d3aad0e38";
gridNo = "4"
break;
default:
}
var formContext = executionContext.getFormContext();
SubGridFilter(formContext, teamGuid, "Subgrid_objectives_" + gridNo, "cr047_objective");
SubGridFilter(formContext, teamGuid, "Subgrid_decisions_" + gridNo, "cr047_decision");
SubGridFilter(formContext, teamGuid, "Subgrid_deliverables_" + gridNo, "cr047_deliverable");
SubGridFilter(formContext, teamGuid, "Subgrid_tasks_" + gridNo, "cr047_task");
};
SubGridFilter = function (formContext, teamGuid, gridName, entityName) {
var phase = formContext.getAttribute("cr047_phase").getValue();
formContext.ui.setFormNotification("team: " + teamGuid + " phase:" + phase + " gridname:" + gridName + " entity:" + entityName, "INFO", "_myUniqueId");
var FetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='" + entityName + "'>" +
"<attribute name='cr047_project' />" +
"<filter type='and'>" +
"<condition attribute='cr047_phase' operator='eq' value='" + phase + "' />" +
"<condition attribute='cr047_team' operator='eq' value='" + teamGuid + "' />" +
"</filter>" +
"</entity>" +
"</fetch>";
var gridContext = formContext.getControl(gridName);
gridContext.setFilterXml(FetchXml);
formContext.getControl(gridName).refresh();
};
WarrenBelz
146,660
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,999
Most Valuable Professional