Microsoft D365 FnO - Set the default value of "Send notifications in email" checkbox in User options > Workflows to true - axapta

I have a requirement to change the default value of a checkbox in SysUserSetup form to true. The data source of this field is SysUserInfo > EventWorkflowTasksInEmail. I have tried to do this by writing the following code in post event handler of initValue method of the table:
[PostHandlerFor(tableStr(SysUserInfo), tableMethodStr(SysUserInfo, initValue))]
public static void SysUserInfo_Post_initValue(XppPrePostArgs args)
{
SysUserInfo sysUserInfo = args.getThis() as SysUserInfo;
sysUserInfo.EventWorkflowTasksInEmail = NoYes::Yes;
}
But the value of checkbox is still false. Can anyone suggest if I am missing something ?
Edit : I debugged my code and found that the customization is not being executed , any reason why ?
The method gets executed when I import users from AAD and the change is working fine but it does not work when I create a new user from D365 itself , is there a way to achieve the latter ?

Related

Devexpress XAF (Blazor) Popup window to edit property

I have an XAF application. Most of my Business Objects are based on a baseclass "MyBaseClass" which contains Createdby, ModifiedBy, ... Comments. The Comments field is AllowEdit=false. I only want users to be able to modify the comment thru an action which would allow them to create an entry to which I would prepend their UserName and timestamp.
I don't know how to pop up a window to edit a property (string) within the current object and view.
There are plenty of examples of how to CreateListView but in this case what I wish to edit in the popup is not a separate BO but just a string. Maybe that is my problem(???)
I have the Action Controller and I am not sure how to create the DetailView when I get into the _Execute()
In Winforms XAF I add an action in a view controller.
In the action's execute event I call something like
private void actOpenDetailView_Execute(object sender, SimpleActionExecuteEventArgs e)
{
var application = Controller.Application
var viewId = application.FindDetailViewId(typeof(MyBusinessObject));
application.CreateObjectSpace(typeof(MyBusinessObject));
var detailView = application.CreateDetailView(newObjectSpace, jh, true);
e.ShowViewParameters.CreatedView = detailView;
e.ShowViewParameters.TargetWindow = TargetWindow.NewWindow;
}
I haven't tried that in Blazor.

VS2022 extensions command initial checked state

I have a VS extensions command based on the default template. It has CommandFlag's TextChanges and TogglePatternAvailable. Depending on a config setting its initial state should be checked, however, this does not appear to be possible.
This is what I want to see on the first load:
I've tried setting Checked to true in the constructor of the command after creating the menu item:
menuItem1 = new OleMenuCommand(ExecuteCommand1, _, BeforeQueryStatus, new CommandID(CommandSet, Command1Id));
menuItem1.Checked = true; // This does not work
I've also tried using the BeforeQueryStatus to change the initial checked state, but it does not seem to be called when opening the Tools menu. Could this be a bug???:
private void BeforeQueryStatus(object sender, EventArgs e)
{
ThreadHelper.JoinableTaskFactory.Run(async delegate
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
menuItem1.Checked = true;
});
}
Clicking the menu item once does trigger BeforeQueryStatus and the state is checked after that, proving that the code does work.
How can I set the initial checked state of the menu item to true depending on a config setting, so in code?
In the end I managed to get it to work by adding the ProvideAutoLoad attribute to my Package. It is unclear if this is the correct way to do this. The pacakge class now looks like this:
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[Guid(PackageGuidString)]
[ProvideMenuResource("Menus.ctmenu", 1)]
[ProvideAutoLoad(VSConstants.UICONTEXT.NoSolution_string, PackageAutoLoadFlags.BackgroundLoad)]
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionExists_string, PackageAutoLoadFlags.BackgroundLoad)]
public sealed class MyPackage : AsyncPackage { ... }

What is gluon Alert generic type?

I went through some documentations here and here and found that gluon dialogs Can* have a generic type which will be the generic type of the object to be returned when you call showAndWait(). But gluon alerts (com.gluonhq.charm.glisten.control.Alert which is a subclass of com.gluonhq.charm.glisten.control.Dialog) does not seem to have a generic type and does not also seem to allow you to give it a generic type.
The problem occured when I tried to call setOnHidden as:
boolean shown;
String report = "";
Alert al = new Alert(AlertType.ERROR);
al.setContentText(report);
al.setAutoHide(false);
al.setOnHidden(e->{
shown = false;
});
shown = true;
al.showAndWait();
and I got the following warning on the setOnHidden() Call:
The method setOnHidden(EventHandler) belongs to the raw type Dialog. References to generic type Dialog should be parameterized
Any clarifications about gluon dialogs or ways to get rid of the warning are most welcome.
Like in the built-in JavaFX Alert control, the implicit type of the Gluon's Alert control is the same: the JavaFX built-in ButtonType, so if you click the OK button, it will return ButtonType.OK.
As you can see at the Alert JavaDoc, the control has one or two default buttons: an OK button for all of them, and a Cancel button for the Confirmation alert. Each of these buttons has as default result ButtonType.OK and ButtonType.CANCEL.
So this works for both Alert controls:
alert.showAndWait().ifPresent(result -> {
if (result == ButtonType.OK) {
// do something;
}
});
One of the things you will notice with both OK and Cancel buttons: the alert will be dismissed, so you don't have to do it.
You can also provide your custom buttons. Then you'll need to take care of calling hide():
final Button myYesButton = new Button("Yes");
myYesButton.setOnAction(event -> {
alert.setResult(ButtonType.YES);
alert.hide();
});
alert.getButtons().add(myYesButton);
About the setOnHidden, see Javadoc. It requires a LifecycleEvent:
alert.setOnHidden((LifecycleEvent event) -> System.out.println("alert hidden"));
but you can use just:
alert.setOnHidden(event -> System.out.println("alert hidden"));
Finally, make sure you are importing the right control:
import com.gluonhq.charm.glisten.control.Alert;
...
Alert alert = new Alert(javafx.scene.control.Alert.AlertType.ERROR);

how to set autosum property in x++ for a morphx report

I have the following code in the init() of a report:
QueryBuildDataSource qbdsTable;
QueryOrderByField QueryOrderByFieldTransDate;
QueryOrderByField QueryOrderByFieldDimZone
QueryOrderByField QueryOrderByFieldDimCC;
;
super();
qbdsTable = query.dataSourceTable(tableNum(Table));
QueryOrderByFieldTransDate = qbdsTable.addOrderByField(fieldNum(Table, TransDate));
QueryOrderByFieldTransDate.autoSum(true);
QueryOrderByFieldDimZone = qbdsTable.addOrderByField(fieldNum(Table, DimZone),SortOrder::Descending);
QueryOrderByFieldDimZone.autoSum(true);
QueryOrderByFieldDimCC = qbdsTable.addOrderByField(fieldNum(Table, DimCostCenter));
QueryOrderByFieldDimCC.autoSum(true);
and the autosum property is functioning properly (I have set the SumAll property for the field I use to calculate these subtotals).
The problem is that, whenever I try to add an groupBy field or a selection field, the autosum property isn't honored anymore (the subtotals are not displayed anymore):
qbdsTable.addSelectionField(fieldNum(Table, AmountMST), selectionField::Sum);
or
qbdsTable.addGroupByField(fieldNum(Table, TransDate));
I have tried to use:
qbdsTable.addSortField(fieldNum(Table, TransDate));
qbdsTable.autoHeader(1, true);
but I have the same problem
Does anyone has an Idea how I can use both autosum and addGroupByField on the same datasorce of a report?
For historical reasons old style AX reports behaves differently when called directly (run on the report node) or through on a report menu item.
The execution order of the first is:
init
fetch
dialog
The second runs via class RunbaseReportStd in the following order:
init
dialog
fetch
This matters because you have change the query after the user has made any changes.
So move your code changes from init to fetch, like this:
public boolean fetch()
{
QueryBuildDataSource qbdsCustTrans = query.dataSourceTable(tableNum(CustTrans));
;
qbdsCustTrans.addSelectionField(fieldNum(CustTrans, AmountMST), selectionField::Sum);
qbdsCustTrans.addGroupByField(fieldNum(CustTrans, AccountNum));
qbdsCustTrans.addGroupByField(fieldNum(CustTrans, TransDate));
qbdsCustTrans.addGroupByField(fieldNum(CustTrans, CurrencyCode));
//info(qbdsCustTrans.toString());
return super();
}
This will only work, if called through the menu item.
Also, I could not get the auto-sum functionality to work, when added by code.
Instead you will have to add the order by and autosum using Sorting node of the report query.
I don't know why, but maybe this is because you use auto design, which is generated at run time.

Custom Validator with an OR Condition

Right now i have an asp.net 2.0 app which allows a user to search by the following fields
Location (Required if there is nothing in idnumber field)
Address (Required if there is nothing in idnumber field)
Zip (Required if there is nothing in idnumber field)
**OR**
IDNumber. (Required if there is nothing in any of the other fields)
What i'd like to be able to do is validate this client side on button click and display a summary of errors.
i.e.
if a user leaves every criteria blank. I'd like to display "You must enter a IDNumber or "Location, Address, and Zip to continue"
I've never used the Custom Validation control so here are some questions.
1) Is it able to do this?
2) Does anyone have an example of how to do this?
Thanks
You can use the ClientValidationFunction property of a CustomValidator control to specify a Javascript function that will validate your form. You'll need to write the JavaScript for the validation. Unless you're writing an application where you can be absolutely sure that all of your clients have JavaScript enabled, I highly recommend you also use the OnServerValidate property to also provide server-side validation.
Server-side CustomValidator example: https://web.archive.org/web/20211020145934/https://www.4guysfromrolla.com/articles/073102-1.aspx
Client-side example: http://www.codeproject.com/KB/custom-controls/CustomValidatorAndSummary.aspx
It is fairly simple to use a custom validator. Add one to your page, and choose the ServerValidate event, which will generate a function like this (example in C#):
protected void CustomValidator1_ServerValidate(object source,
ServerValidateEventArgs args)
{
// Your validation logic goes here... set args.IsValid = true if it passes,
// false otherwise. Here is an example...
args.IsValid = false;
if(txtIDNumber.Text.Length > 0)
{
args.IsValid = true;
}
else if (txtLocation.Text.Length > 0
&& txtAddress.Text.Length > 0
&& txtZip.Text.Length > 0)
{
args.IsValid = true;
}
}

Resources