Redigera

Dela via


Make fields mandatory by using workspace classes

Important

The finance and operations (Dynamics 365) mobile app and platform are no longer supported. The platform components supporting the mobile app will be removed in a future update. The mobile app has also been removed from app stores. Previously installed instances of the app will continue to work. For more information, see Removed or deprecated platform features.

When you use the mobile app designer to select fields for actions, some properties can be inferred. These properties include the field length, the type, and whether the field is mandatory. The workspace classes can be used to update these properties. For example, you might want to specify that the Name field is mandatory when a customer record is created, as shown in the following images.

Action and fields.

Action that has a mandatory field marked.

Follow these steps to make the Delivery terms field mandatory by using the workspace class.

  1. Get the control name by using the app designer. In this example, the control name is DynamicDetail_DlvTerm.

  2. Add the following code to set the Mandatory property for the control. This code uses the reflection-based setProperty method to set the Mandatory property.

    public SysAppWorkspaceMetadata getWorkspaceMetadata()
    {
        SysAppWorkspaceMetadata appMetadata;
        appMetadata = super();
        var createCustAction = appMetadata.getAction("createCust");
        this.setCustAccountMandatory(createCustAction);
        return appMetadata;
    }
    private void setCustAccountMandatory(SysAPpActionMetadata _createCustAction)
    {
        var custAccount = +createCustAction.getControl("DynamicDetail_DlvTerm");
        custAccount.setProperty("Mandatory", true);
    }
    
  3. Build the solution, and then update the app metadata on the mobile app.

The Delivery terms field is now marked as Mandatory, as shown in the following illustration.

Delivery terms field is marked as mandatory.