Make a multiobjectpicker required in a custom form
Hi Guys!
We have added a mutliobjectpicker for business services in the SR form. My client would like to have this field as required.
This is the code i'm using in the custom form:
{
name: "Business Service",
type: "multipleObjectPicker",
PropertyName: "HasRelatedWorkItems",
ClassId: "b2a806a6-87f6-0bc9-da74-c27e9ab5a5d7",
PropertyToDisplay: {DisplayName:"Name", "Priority.Name":"Priority"},
Scoped: true,
},
Does anyone know if this is possible? I have tried to add: Required: true but it does not seem to work. Unfortunatly i'm not very familiar with this kind of coding.
Best Answer
-
Geoff_Ross Cireson Consultant O.G.Hi Simon,
Unfortunately, with a multi picker, Required: true, will not work as I guess 0 objects fulfils with requirement of 'multi.
There's a couple or work arounds I've used in the passed. Both require a bit of custom javascripting.
1. Simple (er) solution: Add a property of the class called BusinessServiceValidation. Add this to the form as a required field but disabled so it cannot be edited manually. Then run custom code that triggers on the change of the Business Service Object multi-picker that counts the number of selected objects, and if its greater then 1, writes the string 'Valid' into the BusinessServiceValidation property. If its zero, it clears the BusinessServiceValidation property. As this property is required, the form will not save if its blank and the property will show in red so its clear what needs adding. The same logic will need to fire on page load too to set / clear the BusinessServiceValidation property.
2. More complex but more elegant solution. Have some code running that detects when then save button is clicked via the API call that will run on this click. Then check the logic (as above) and either allow the save or redirect back to the page.
Good luck.5
Answers
Unfortunately, with a multi picker, Required: true, will not work as I guess 0 objects fulfils with requirement of 'multi.
There's a couple or work arounds I've used in the passed. Both require a bit of custom javascripting.
1. Simple (er) solution: Add a property of the class called BusinessServiceValidation. Add this to the form as a required field but disabled so it cannot be edited manually. Then run custom code that triggers on the change of the Business Service Object multi-picker that counts the number of selected objects, and if its greater then 1, writes the string 'Valid' into the BusinessServiceValidation property. If its zero, it clears the BusinessServiceValidation property. As this property is required, the form will not save if its blank and the property will show in red so its clear what needs adding. The same logic will need to fire on page load too to set / clear the BusinessServiceValidation property.
2. More complex but more elegant solution. Have some code running that detects when then save button is clicked via the API call that will run on this click. Then check the logic (as above) and either allow the save or redirect back to the page.
Good luck.