In my previous blog post, I wrote about goal management in general (link to article here). The post explains how goal management works and how to configure it yourself. Adding goals in bulk is one of the gaps I noticed while I was looking into this feature. Yes, there is always the option to go for the Excel route, of course, but in this post, I would like to demonstrate how you can build something yourself so adding goals in bulk will be simple and easy.
From a functional or process perspective, you need to decide what the philosophy is. In my use case for Padel Vamos, I would like to create the goals for an owner, for certain goal metrics, and for the remaining months of the current year.
Technically, this means that I need to create the following:
- a new Button on the goal management form
- a Custom page that is collecting the required information
- a Power Automate Flow to process all of this
Add Goals Bulk button
First, you need to make sure that you create a new custom button that will eventually launch the custom page. Follow the next steps to do this:
- Navigate to https://make.powerapps.com/
- Edit the Model-Driven App where you want to add this button to
- Add or find the Goals view and select the three dots > Edit command bar > Edit

- Select Main Grid and press Edit
- Add a button via + New > Command
- Set the following properties:
- Icon = either a standard or upload one yourself
- Action =Run JavaScript
- Library = I have built a custom library with functions to open dialogs
- Function = openCustomPageDialog
I will not go into too much detail on this. The JavaScript code is below, where I believe the most important bit is the name of your custom page: jsc_goalbulkadding_74275. If you are interested in this topic, then there are great people in the community who have written in detail about this, like Matthew Devaney, so check out his post about that here, since he explains it really well.
function openCustomPageDialog(primaryControl, firstSelectedItemId, selectedEntityTypeName)
{
// Centered Dialog
var pageInput = {
pageType: "custom",
name: "jsc_goalbulkadding_74275",
entityName: selectedEntityTypeName,
recordId: firstSelectedItemId
};
var navigationOptions = {
target: 2,
position: 1,
height: {
value: 500,
unit: "px"
},
width: {
value: 50,
unit: "%"
},
title: "Goal Management - Bulk Add Goals"
};
Xrm.Navigation.navigateTo(pageInput, navigationOptions).then(
function () {
// Refresh the main form when the dialog is closed
primaryControl.data.refresh();
}
).catch (
function (error) {
// Handle error
}
);
}

Custom page: Adding goals in Bulk
When it comes to the custom pages, I would like to share again that there are great people in the community who can share a lot more about the best practices, for example, Megan Walker, who is now writing a whole series on this topic, so check it out here if you are interested in this topic.
For the creation of goals, there are a few key things that are needed, but also some decisions to make on how this can work for you:
- Goal Owner: to whom will this goal apply
- Goal Metric, so for which metric do I want to add the goals in bulk
- What is the Target
- The one that is not on this list, but was the most difficult one was the Goal Period.
Standard, probably the easiest one is the Quarterly periods. In my example, I want to go for the custom route and do this per month 😅😁

The cosmetic changes I will not explain in detail in this post, since the most important one to explain is the OnSelect of the Save button. In this statement, we trigger the Power Automate Flow with the Guids and values of the custom page.
Power Automate Flow, where the magic happens
This is the bit of adding goals in bulk that I do like to focus on. Most of the time of this feature is spent here.

Additional information per step:
Initialize variable – Current month:
int(formatDateTime(utcNow(), 'MM'))
Initialize variable – Current Year:
int(formatDateTime(utcNow(), 'yyyy'))
Initialize variable – Last Day of Month:
subtractFromTime(startOfMonth(addToTime(utcNow(),1,'month')),1,'day','dd')
Add Goal
Name is a concatenation of Owner, Metric, Year, and Month
concat(items('For_each')?['fullname'], ' - ', outputs('Get_Goal_Metrics_by_GUID')?['body/name'], ' - ',variables('VarCurrentYear') ,'-',variables('varCurrentMonth'))
From is the first day of Month
formatDateTime(concat(utcNow('yyyy-'), variables('varCurrentMonth'), '-01'), 'yyyy-MM-dd')
To is the last day of Month
formatDateTime(concat(utcNow('yyyy-'), variables('varCurrentMonth'),'-', variables('LastDayOfMonth')), 'yyyy-MM-dd')
Set variable – Set Last Day of Next Month
The last day of the next month is being calculated from today’s date, which means varNumberOfMonths is crucial to have in order to calculate the right last date of the month
subtractFromTime(startOfMonth(addToTime(utcNow(),variables('VarNumberOfMonths'),'month')),1,'day','dd')
Overall, this was a fun experience to build, and if you have resolved this differently or have different thoughts about this, then feel free to share something in the comments.
My next post will also be on the topic of Goal Management and another gap I experienced, which will even be more fun.