Skip to main content

Notifications

Community site session details

Community site session details

Session Id : hZLNQ0zebQk4M4u3c+VVtT
Power Apps - Building Power Apps
Answered

Namespaces in javascript

Like (0) ShareShare
ReportReport
Posted on 9 Jun 2022 17:10:41 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:
  • v-xiaochen-msft Profile Picture
    on 13 Jun 2022 at 09:05:54
    Re: Namespaces in javascript

    Hi @Rydman ,

     

    Yes, you could customize the namespace.

     

    Best Regards,

    Wearsky

  • Rydman Profile Picture
    96 on 13 Jun 2022 at 08:49:55
    Re: Namespaces in javascript

    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!

  • Verified answer
    v-xiaochen-msft Profile Picture
    on 13 Jun 2022 at 08:39:17
    Re: Namespaces in javascript

    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 13 Jun 2022 at 08:06:44
    Re: Namespaces in javascript

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

     

  • v-xiaochen-msft Profile Picture
    on 13 Jun 2022 at 06:42:35
    Re: Namespaces in javascript

    Hi @Rydman ,

     

    Could you share your script?

     

    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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,660 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,999 Most Valuable Professional

Leaderboard
Loading started