web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Namespaces in javascript
Power Apps
Answered

Namespaces in javascript

(0) ShareShare
ReportReport
Posted on by 96

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:

 

Rydman_0-1654794336269.png

 

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!

Categories:
I have the same question (0)
  • v-xiaochen-msft Profile Picture
    on at

    Hi @Rydman ,

     

    Could you share your script?

     

    Best Regards,

    Wearsky

  • Rydman Profile Picture
    96 on at

    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();
    
    };
    

     

  • Verified answer
    v-xiaochen-msft Profile Picture
    on at

    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

  • Rydman Profile Picture
    96 on at

    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!

  • v-xiaochen-msft Profile Picture
    on at

    Hi @Rydman ,

     

    Yes, you could customize the namespace.

     

    Best Regards,

    Wearsky

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard