- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi
Whenever the below "Dispatch" field is read only then the field named Part Information should be made mandatory.
And Dispatch field gets to be readonly when the form is saved.
So when the dispatch field is checked the part information should not be visible and only when the form gets saved and the dispatch field is read only the part information field is made visible and mandatory
How can we do that
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @Abdul , try the onLoad script below, if this is on catalog form then use catalog client script
Script:
function onLoad() {
var dispatchField = 'dispatch';
var partInfoField = 'part_information';
var isDispatchChecked = g_form.getValue(dispatchField) == 'true';
var isDispatchReadOnly = g_form.isReadOnly(dispatchField);
if (isDispatchReadOnly && isDispatchChecked) {
g_form.setVisible(partInfoField, true);
g_form.setMandatory(partInfoField, true);
} else {
g_form.setVisible(partInfoField, false);
g_form.setMandatory(partInfoField, false);
}
}
If this solution helps you please don't forget to mark this solution as accepted and helpful, this will help others as well.
Regards,
Saurabh V.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi Abdul,
Try to use 'onload' Client script and create necessary condition to check if the field is readOnly. If the field is readOnly make the other field Mandatory
function onLoad() {
var depatchField= 'depatch_field';
var partInfoField= 'part_info_field';
var isReadOnly = !g_form.isEditableField(depatchField);
g_form.setMandatory(partField, isReadOnly);
}
Please like the feedback if the solution proposed is helpful for you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
i wrote the below code it makes it mandatory whenever the form loads, this field should only be mandatory and visible if the condition such as dispatch check box is true and it is read only.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @Abdul , try the onLoad script below, if this is on catalog form then use catalog client script
Script:
function onLoad() {
var dispatchField = 'dispatch';
var partInfoField = 'part_information';
var isDispatchChecked = g_form.getValue(dispatchField) == 'true';
var isDispatchReadOnly = g_form.isReadOnly(dispatchField);
if (isDispatchReadOnly && isDispatchChecked) {
g_form.setVisible(partInfoField, true);
g_form.setMandatory(partInfoField, true);
} else {
g_form.setVisible(partInfoField, false);
g_form.setMandatory(partInfoField, false);
}
}
If this solution helps you please don't forget to mark this solution as accepted and helpful, this will help others as well.
Regards,
Saurabh V.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
is that Dispatch field already readonly and no one will be changing that?
If yes then you can use onLoad client script
If not then you can use onChange on that checkbox
what did you start with and where are you stuck?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader