how to check whether record exists in related list using BR

sasi
Tera Contributor

Hi ,

i want to check whether there is at least one record in related list , if it is there fine. if there is no record show error message that as "please add one record at least"

and these check has to done when it is changing from new to work in progress.

 

 

12 REPLIES 12

Hi Sasi,

If my answer is helpful please mark my appropriate answer as correct.

 

Hi @Balaji

 

I have the same requirement on change form, incidents pending related list tab should have atleast one entry.

I used the same code on  change table using before business rule (update ) with filter conditions as priority 1 ,breakfix as ABC and classification as DEF 

 

(function executeRule(current, previous /*null when async*/) {
  var inc = new GlideRecord("incident");
  inc.addQuery("parent", current.getUniqueValue()); // set the condition
  inc.query();
  if(!inc.hasnext())
  {
  gs.addErrorMessage(" reject ");
  current.setAbortAction(true);
}
 })(current, previous);
It is throwing the error message but classification value is changing from DEF to xxx(previous value) after adding incident to the related tab and also showing error message if there is an entry already.
 
Can you please help in fixing the code

Community Alums
Not applicable

Hi Sasi,

Here is the code:

Onsubmit script

function onSubmit() {

  var istrue = g_form.getValue('u_relate_to_project');

  if(istrue == 'true')

  {

  var curSysid = g_form.getUniqueValue();

  var ga = new GlideAjax('check_projects_exists');

 ga.addParam('sysparm_name','isProjectExist');

  ga.addParam('sysparm_currentsysid', curSysid);

  ga.getXMLWait();

  var answer = ga.getAnswer();

  if(answer == 'Not Exist')

  {

  alert('please add one record at least');

  return false;

  }

  }

}

__________________________________

 

scriptInclude

 

Name : check_projects_exists

 

Active : true

Client callable : true

Script:

var check_projects_exists = Class.create();

check_projects_exists.prototype = Object.extendsObject(AbstractAjaxProcessor,

 

{

  isProjectExist: function()

  {

  var answer ='';

  var cursysid = this.getParameter('sysparm_currentsysid');

  gs.log('cursysid :'+cursysid);

  var gr = new GlideRecord('task');

  gr.addQuery('parent', cursysid);

  gr.query();

  if(!gr.next())

  {

  answer = "Not Exist";

  }

  else

  {

  answer = "Exist";

  }

  return answer;

  }

});

 

Please mark my answer as Correct & Helpful, if applicable.

Thanks

Sandeep