How do I make a Related List Tabs to be mandatory when a field is selected in the form?

ChuanYanF
Tera Guru

Dear experts,

 

I would like to ask how do I make the three related list tabs below that is bracketed in red to be mandatory according to the fields in the risk event form when a specific choice is selected? I know of the onchange or onLoad client script, but there is no option to make it mandatory how should I approach this matter?

function onLoad() {
    if (g_form.getValue('u_parties_involved_in_affected_by_the_event').toString() == '1') {
		alert('inside');
        g_form.hideRelatedList('sn_risk_advanced_customer_info_breached_customer_s_involved_affected', true);
    }
}

ChuanYanF_0-1746424499973.png

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@ChuanYanF 

you cannot make related list mandatory using client script

You will have to use before update business rule on your main table, check if there are records in related list table or not

If not then stop the form submission

check this link and enhance

Mandatory related list 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

3 REPLIES 3

AdusumalliK
Tera Contributor

Hi,

 

There is no OOTB scripts available to make Related lists mandatory. But You can take an approach of on before business rule by checking that there is at least one entry on the child tables related to the parent record and setabortaction to true in case there are no entries. you can trigger the BR based in field values selected in the record. Or you can trigger the same check via script include and an on-change client script and show a error message on the screen.

 

Please mark helpful if this approach works.

 

Chaitanya ILCR
Kilo Patron

Hi @ChuanYanF ,

It's not possible

there are issues with ask well let's say we were able to make it mandatory if the user clicks on the new button it's throws an error stating fill the mandatory info first (it's not possible but even if it were to work you are going to encounter this issue)

better create a before BR on the table and abort action if no related record is created and throw an error stating create a related record first 

 

or 

 

as soon as user updates the current record create a related record automatically by async or after BR

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

Ankur Bawiskar
Tera Patron
Tera Patron

@ChuanYanF 

you cannot make related list mandatory using client script

You will have to use before update business rule on your main table, check if there are records in related list table or not

If not then stop the form submission

check this link and enhance

Mandatory related list 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader