Loading
Visual Studio Code Based Modeler for Consumer Goods Cloud
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Show Error for Empty Display Name Value

          Show Error for Empty Display Name Value

          Use Visual Studio Code based Modeler to add a validation in the offline mobile app to check that the display name field isn’t empty.

          Required Editions

          Available in: Enterprise and Unlimited Editions where Consumer Goods Cloud is enabled
          User Permissions Needed
          To add validation check in VS Code Modeler Customizer, Developer
          1. To manually create a ValidationMessages contract for BoMyDisplay.businessobject.xml, in VS Code Modeler, right-click the BoMyDisplay folder at $workspace/src/MyDisplay/Bo, and click New File.
            1. Name the file MyBoMyDisplayMessages.validationmessages.xml.
            2. Add this snippet to the ValidationMessages contract.
              This sample code snippet creates a set of validation messages for the BoMyDisplay business object. The code includes the DisplayNameEmpty validation message that prompts the user to enter a value if the name is empty.
              <ValidationMessages name="MyBoMyDisplayMessages" businessObject="BoMyDisplay" schemaVersion="0.0.0.5">
                <ValidationMessage name="DisplayNameEmpty" defaultMessage="Please enter a name." comment="validates entered work times" />
              </ValidationMessages>
            3. Save your changes.
          2. To add a validation method to the BoMyDisplay business object, open the VS Code terminal, run sf mdl add, and enter these details.
            ?Select the resource you want to add. businesslogic
            ?Specify a name for the businesslogic: ValidateNameEmpty
            ?Select the module to which businesslogic 'ValidateNameEmpty' should be added. MyDisplay
            ?Select a suitable option for businesslogic 'ValidateNameEmpty'. method
            ?Select the reference object to which you want to add the businesslogic method. BoMyDisplay
            The CLI creates the BoMyDisplay.MyValidateNameEmpty.bl.js method and adds a reference to this method in the list object of the BoMyDisplay.businessobject.xml contract.
          3. In BoMyDisplay.MyValidateNameEmpty.bl.js, add a parameter called messageCollector to the method.
            * @param {messageCollector} messageCollector
              */
            function myValidateNameEmpty(messageCollector){
                var me = this;
          4. In BoMyDisplay.MyValidateNameEmpty.bl.js, add this code.
            var newError;
            if(Utils.isEmptyString(me.getName())){
              newError = {"level": "error",
                          "objectClass": "BoMyDisplay",
                          "messageID": "DisplayNameEmpty"};
              messageCollector.add(newError);
            }
          5. To specify the method as validation method, in BoMyDisplay.businessobject.xml, move the method to the validations section of the contract.
            <Validations>
              <Validation name="myValidateNameEmpty"/>
            </Validations>
          6. Refresh locales to populate the validation message. To make the new message available in the locale file the locale file has to be refreshed.
            1. Build the contracts by running this command. sf modeler workspace build.
            2. Run the command: sf modeler workspace refreshLocales
            3. Save your changes.
            The framework collects the label snippets from the different contracts and refreshes the locale file.
          7. To verify that that validation is executed in the process:
            1. Refresh the simulator app in the browser.
            2. In the Display master-detail page, clear the value of the name field for any one of the display records.
            3. Click another row in the master list to trigger a save action. A warning appears as shown here.

              This offline mobile app screen capture shows the error message when the name field is empty on the master detail page of Displays.

           
          Loading
          Salesforce Help | Article