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

You need to write a business rule on the change_request table to validate that there is a change verification record in the related table or else abort the change processing



Thank You


Please Hit Like, Helpful or Correct depending on the impact of response


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

champ
Kilo Contributor

shlokesrivastava@outlook.com



I have verification list on the change form, which contains user to be added on the related list.



I wrote the below business rule but does not work out.





Script: (function executeRule(current, previous /*null when async*/) {     // Add your code here     var usr = new GlideRecord("sys_user");     usr.addEncodedQuery("parent=" + current.sys_id);     usr.query();     if(!usr.next())     {     gs.addInfoMessage("Please link a Problem Record at the bottom Verification Tab");     action.setRedirectURL(current);     current.setAbortAction(true);     } })(current, previous) It throws error


Hi,



Everything looks good in the script shared above except the Table Name in your Glide Record Query i.e. it should not be User(sys_user) table but it should be the Related List Table i.e. Verification Table in your scenario where you are trying to add the User Record on the Parent Change form. Update the Correct Table Name in the Query and try the below script again to check for the functionality.



Update your Code as per the below mentioned:



Script:



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




  // Add your code here


var usr = new GlideRecord("Table Name");   //Replace here the Related List table i.e Table where you are adding the User Record on Change Form


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


usr.query();


if(!usr.next())


  {


  gs.addInfoMessage("Please link a User Record at the bottom Verification Tab");


  action.setRedirectURL(current);


  current.setAbortAction(true);


  }




})(current, previous);




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

champ
Kilo Contributor

Perfect