Recently we got the below error while trying to assign the record.
Unable to save. This form can’t be saved due to a custom setting.
Turned out we had certain conditions in the OnSave event for the form, and if the record satisfies those conditions we were canceling the save event using
In Dynamics 365, there are instances when we need to dynamically change the labels of option set fields based on specific conditions. For example, we might want to update the label of the “Priority” field option from High to Critical when a case is marked as escalated (Is Escalated = True).
Below is the sample code we can use for it. The code will be registered on the OnLoad for Form and OnChange of Is Escalated field.
function SetLabel(executionContext)
{
var formContext = executionContext.getFormContext();
var isEscalated = formContext.getAttribute("isescalated");
var optionSetControl = formContext.getControl("prioritycode"); // field is in header and not in form
var optionHigh = 1; // high
var newLabel = "Critical";
if(optionSetControl && isEscalated.getValue() == true)
{
var options = optionSetControl.getOptions();
for (var i = 0; i < options.length; i++) {
if (options[i].value === optionHigh) {
optionSetControl.removeOption(optionHigh);
optionSetControl.addOption({
text: newLabel,
value: optionHigh
});
break;
}
}
}
}
On opening the form, we can see the Priority’s value High changed to Critical in case Is Escalated = Yes.
var formContext = executionContext.getFormContext(); = This retrieves the form context from the execution context, which is essential to interact with the form’s attributes and controls.
var isEscalated = formContext.getAttribute(“isescalated”) = The isescalated attribute is used to determine whether the case is escalated.
var optionSetControl = formContext.getControl(“prioritycode”);
The current options are retrieved using getOptions().
The option with the value 1 (High priority) is removed.
A new option with the updated label “Critical” and the same value is added.
However, one interesting thing to note is the Header still shows the old value High, it seems there is no supported way to change the label in case if the field is used in the Header.
We can use the setIsValid method for validating field values in Model-driven apps. This method helps ensure that the data entered by users meets the required criteria before it’s processed or saved.
The setIsValid method is used to set the validity of a column’s value. It can mark a field as valid or invalid based on custom validation logic.
bool: A Boolean value. Set to false to mark the column value as invalid, and true to mark it as valid.
message: (Optional) A string containing the message to display when the value is invalid.
Below we are using the setIsValid method in the function that ensures that the “End Date” is earlier than or equal to the “Start Date”, else it will mark the “End Date” as invalid.
function validateDates(executionContext) {
var formContext = executionContext.getFormContext();
var startDate = formContext.getAttribute("custom_startdate");
var endDate = formContext.getAttribute("custom_enddate");
if (startDate && endDate && endDate.getValue() <= startDate.getValue()) {
endDate.setIsValid(false, "End Date must be after Start Date.");
} else {
endDate.setIsValid(true);
}
}
We have it registered in the On Change of the ‘Start Date’ and ‘End Date’ fields.
Here if we try saving the record, if the End Date is smaller than the Start Date, we will get the message specified.
In Dataverse, solution dependencies are a vital aspect of managing and deploying applications. Dependencies ensure that required components are present for a solution to work seamlessly across environments. However, with complex solutions, understanding and managing these dependencies can become overwhelming.
The updated dependencies page is designed to simplify dependency management by offering a more intuitive, action-driven experience.
Select a particular component in the solution, right-click>> Advanced >> Show dependencies.
We can see 3 different tabs.
Delete Blocked By (tab): Displays any dependencies preventing deletion of a component. Below we can see that for the Age column, it shows Contact’s System Form as the dependency.
Clicking on the Open option takes us to the component page, where we can see all the forms for the contact table.
Used By (tab): Lists other components dependent on the selected component.
Uses (tab): Shows dependencies that the selected component relies upon.
On clicking Open, it opens the Columns page for that table.
The different actions that we can take are Open and inspect the object, Delete the object, Remove dependency, and open the relevant documentation.
Below we have selected the option Remove dependency. As we saw the dependency here refers to the Contact System form in which we have the age field used.
Select Remove.
We get the success message after the successful removal of the dependency.
i.e. we can see the field removed from the blocking Contact’s System form.
Now if we want we can easily delete that particular field with no object blocking the delete.
Lastly, the Delete option for the solution allows the delete (uninstall) the solution that has dependencies on the solution component.
Using the new features – Create a formula (preview) and Explain this formula we can now easily write, edit, and understand formulas in Power Apps.
To enable it, navigate to switch on – Settings >> Updates >> Preview >> Copilot for formulas
Here in the sample app below, we are trying to set the Items property of the Gallery using Create a formula. Here our gallery control is bound to Cases as the data source.
We can describe what formula we need in plain language.
We can see it generating the formula for us. We have the option to Apply, Discard, and Copy it.
Here we have applied the generated formula.
Another example is where we are setting the Text property.
Here instead of the customer name it considered the Customer Contacted field. So basically we need to review the formula generated.
We can also generate formula from code comments as show below. Simply type the comment and wait for formula to be generated or otherwise press Enter.
The result
Next using Explain this formula we can use the copilot’s ability to explain the formula in plain language.
The result
We can also select specific parts of the formula for explanation.
Below we have selected the Filter keyword and Explain this selection option.
Field Suggestions by Copilot for Canvas Apps apply to Gallery, Form Table controls both classic and modern for Dataverse, SharePoint, or SQL Server data source. It analyzes the schema of the table selected and recommends up to 10 fields that also include a maximum of 10 required fields of that table.
Let us see it in action.
Below we have the following fields defined as required fields in the lead table.
Now inside CanvasApp when we insert and bind the Modern Form / Table or the classic Edit Form / Display Form, Data Table to the lead table it automatically suggests the fields for binding.
Here we have selected Lead as the Data Source for the Edit form or Form (modern) control.
Here we can see it suggesting all the required fields of the lead along with other key fields of lead like City, Country, Email, First Name, etc.
In the case of Table, we can see it suggesting the following 10 fields.
In the case of a custom table with very few fields in it, it suggested the below fields for Form and Table control.