Please see the code example below that restricts the Quantity column to be equal 6. Please make sure that you are using the internal name of the column in the code.
fd.spRendered(function() {
fd.control('SPDataTable1').$on('edit', function(editData) {
editData.field('Currency').validators.push({
name: 'MyCustomValidator',
error: '',
validate: function(value) {
if (value != 6) {
this.error = 'Value must by greater than 0';
return false;
}
return true;
}
});
});
});
When user selects 'Surgical Mask Replacement' from the parent field, i want 'Surgical masks' to auto-populate in the List or Library control when New Item is created:
fd.spRendered(function() {
function setSurgical() {
if (fd.field('BusiinessJustification').value == 'Surgical Mask Replacement') {
// Setting the ProjectHealth to Major Concerns
editData.field('Title').value = 'Surgical masks';
}
}
// Calling setPercentComplete when the user changes the status
fd.field('BusiinessJustification').$on('change',setSurgical);
// Calling setProjectStatus on form loading
setSurgical();
});
For your case, you need to add the condition, please see the example below:
fd.spRendered(function() {
//prepopulating fields of a new record
//with the values from the parent form
fd.control('SPDataTable1').$on('edit', function(editData) {
//check that this is a new record
if (editData.formType === 'New') {
if(fd.field('BusiinessJustification').value == 'Surgical Mask Replacement') {
//prepopulating title
editData.field('Title').value = 'Surgical masks';
}
}
});
});
@mnikitina thanks for your response. I forgot to mention that the 'Title' column is a lookup. So I modified your code to reference "value.LookupValue" but it's still not working. Any suggestions?
fd.spRendered(function() {
//prepopulating fields of a new record
//with the values from the parent form
fd.control('SPDataTable1').$on('edit', function(editData) {
//check that this is a new record
if (editData.formType === 'New') {
if(fd.field('BusiinessJustification').value == 'Surgical Mask Replenishment') {
//prepopulating title
editData.field('Title').value.LookupValue = 'Surgical masks';
}
}
});
});
You can set the lookup value with the ID only, please see the code below.
fd.spRendered(function() {
//prepopulating fields of a new record
//with the values from the parent form
fd.control('SPDataTable1').$on('edit', function(editData) {
//check that this is a new record
if (editData.formType === 'New') {
if(fd.field('BusiinessJustification').value == 'Surgical Mask Replacement') {
//prepopulating title
editData.field('Title').ready().then(function() {
//replace 0 with the item ID
editData.field('Title').value = 0;
});
}
}
});
});
@mnikitina thanks it worked! Just one more question:
if (fd.field('BusiinessJustification').value == 'Surgical Mask Replacement'), restrict SPDataTable1 field 'Quantity' value to a maximum of 6. ('Quantity' is not a lookup field).
@mnikitina is it possible to ad a validation function on the Child 'SPDataTable1' green check mark? I want the green check mark to be required to check off prior to saving the Parent form.