Mandatory related list

karshauliya
Kilo Contributor

I would like to make mandatory

1 ACCEPTED SOLUTION

shloke04
Kilo Patron

Hi,



In order to make the Related List Mandatory i.e. checking if any record is present in the Related List or not we can make use of an Before Update Business Rule and Abort the Form Submission as required. Please follow the below steps:



1) For Example On the Incident Form, I have the Problem Related List and say based on certain condition you want to check whether the Problem Related List has Records attached or not whether a New one or an existing one then we can have the below script and make the Related List as a mandate one:



Script:



(function executeRule(current, previous /*null when async*/) {




  // Add your code here


  var prb = new GlideRecord("problem");


  prb.addEncodedQuery("parent=" + current.sys_id);


  prb.query();


  if(!prb.next())


  {


  gs.addInfoMessage("Please link a Problem Record at the bottom Probem Tab");


  action.setRedirectURL(current);


  current.setAbortAction(true);



  }




})(current, previous);




find_real_file.png



find_real_file.png



Result:



If the User tries to Update the Record without attaching the Problem Record it aborts the form submission with the Invalid Update Error as shown below:



find_real_file.png



Hope this helps.Mark the answer as correct/helpful based on impact.



Regards,


Shloke


Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

13 REPLIES 13

If your query is Resolved, would you mind marking the answer as correct and close the thread.



Regards,


Shloke


Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Would you mind marking the answer as correct and close the thread so that this can be removed from Unanswered List.



Regards,


Shloke


Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hi,

 

I am trying to achieve the same requirement using your code, here i want to make the outage record mandatory when priority is high. below is my changes in your code which is on condition "before" update or insert. under filter, priority is p1 or p2.

(function executeRule(current, previous /*null when async*/) {

// Add your code here
var out = new GlideRecord("cmdb_ci_outage"); /


out.addEncodedQuery("parent=" + current.sys_id);


out.query();

if(!out.next())


{


gs.addErrorMessage("Please link a Outage Record");
current.setAbortAction(true);


}




})(current, previous);

 

 

shloke04
Kilo Patron

Hi,



If your Query is Resolved, Mark the answer as correct and close the thread for others.



Regards,


Shloke


Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke