This project is read-only.

Dynamic Forms - Adding Model Erorrs

Topics: Core
Jun 19, 2015 at 8:10 PM
Hi Sipke,

I have a couple more questions around Dynamic Forms and Adding Model Errors. Where can I find documentation on syntax for the Add Model Error fields? Do you have an example somewhere of using the Dynamic Form Validating activity with Add Model Error? I have setup the following script in a decision...

if ( "#{FormSubmission.Field:PayType}" != "CONTRACTOR" && "#{FormSubmission.Field:EmployeeFileNumber}" == "") { SetOutcome("FAIL"); } else { SetOutcome("PASS"); }

If the outcome is FAIL I have it going to an Add Model activity with the following info.

Key: EmployeeFileNumber

Error Message: Employee File Number is required if Pay Type is not Contractor.

Questions are: 1) Does the key have to be the tokenized field name like "#{FormSubmission.Field:EmployeeFileNumber}", or the HTMLID or something else? 2) Does the Error Message need to be in double quotes?, and 3) Should the Validating workflow be separate from the submission workflow or can you combine them? On the last one I guess I am asking more of what would be the best practice?

Thank you,


P.S. - I put this post in the previous discussion chain, but I thought that one was getting to long so I started a new one.
Jun 20, 2015 at 9:38 AM
Edited Jun 20, 2015 at 9:39 AM

There's no documentation yet, but this is how you use the activity:
  • For the Key field, provide the exact same name as the Name value of the form field element.
  • For the Error Message field, provide the error message you'd like to show.
To answer your questions:
  1. No, it simply needs to resolve to the actual form field Name. For example, if your field element has its Name property set to EmployeeFileNumber, that's the value you provide for the Key field of the AddModelError activity. If you do provide a token, it needs to evaluate to the form field name you want to add a model validation error for. However, I'd say that in most cases, you won't use a token here.
  2. No, don't use quotes unless you want to actually display quotes as part of your validation error message.
  3. Good question, I don't know. It would probably my personal default to have both Validating and Submitted events be part of the same workflow because it seems to make sense to have those things be in one place, visualizing the complete workflow of my business process. If you can;t for some reason, it's fine to have two workflows, because the Submitted event will not be triggered if there are any model validation errors.
Marked as answer by RG29 on 6/23/2015 at 12:54 PM
Jun 20, 2015 at 2:06 PM

Thank you for the info. Especially on a weekend. I wasn't expecting anything until Monday. I will give this a shot and let you know how it turns out. Again, really appreciate the information and guidance you have provided.

Thank you,

Jun 22, 2015 at 1:37 AM
Edited Jun 22, 2015 at 12:45 PM
Hi Sipke,

I used the following script on a decision activity in the Dyanmic Form Validating workflow and I am never getting anything back for a value. It is always coming back with an empty string. Employee File Number is a text field. Any ideas as to why this would always be an empty string? Can I not use FormSubmission in a Validating workflow? If not, what can I use to get the value in the text field?

if ( "#{FormSubmission.Field:EmployeeFileNumber }" == "" ) { SetOutcome("FAIL"); } else { SetOutcome("PASS"); }

Thank you,

Jun 22, 2015 at 12:45 PM

I just tried on a different text field and it does the same thing. It works on select lists, but not on text fields. I can get the value of the select list using the syntax below, but the same syntax does not work for text fields. Am I doing something wrong here? Again to clarify this is in a Dynamic Forms Validating workflow.

if ( "#{FormSubmission.Field:PayType}" != "CONTRACTOR" ) { SetOutcome("NON-CONTRACTOR"); } else if ( "#{FormSubmission.Field:PayType}" == "CONTRACTOR" ) { SetOutcome("CONTRACTOR"); }

Thank you,

Jun 22, 2015 at 4:04 PM

I just figured out the issue on the text field and validation errors. I feel kinda stupid. The problem was in my script. You have to be very careful with the syntax. I had a space between the curly brace(s) and the "FormSubmission.Field:EmployeeFileNumber". This was causing it to fail every time whether I had a value in the text field or not because it was always coming up with an empty string. Most of the examples I have seen were like this though which is kind of concerning. Spaces do not seem to make a difference in the SetOutcome portion of the script, but it definitely does in the "if" condition. I am going to test this some more, but it appears that this is the problem. When I get through with this project I may put some documentation together with some screen shots on everything that I have learned while building a dynamic form. If I did this would you like me to send it to you so you can post it on your site?

Thank you,

Jun 22, 2015 at 6:57 PM
Nice catch! Happy to see you're making progress. If you could write some documentation that would be absolutely fantastic. If it's documentation, then I think it would be best to submit a pull request for the documentation here: If it's more of a blogpost kind of format, then perhaps it's best if you write it as such and tweet about it. We'll link to it from the Orchard Project homepage.

Thank you
Jun 22, 2015 at 8:34 PM
Edited Jun 23, 2015 at 8:54 PM
Started new thread...