Make entry in related list mandatory

LG2
Mega Expert

Hi,

We have a simple ttue/false field in our change form - u_relate_to_project - default is false

On submit, If this field is true, I need to check to make sure that there is at least one entry in the project>parent related list (which we also display on the change form related lists), if not then the user will get a notice to say they have to complete the project details.

Any suggestions please?

thanks

We are using Dublin Patch 7 and Project Management v3

1 ACCEPTED SOLUTION

Hi LG,



              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 select one project');


  return false;



  }




  }



}



__________________________________


Includescript



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;



  }


});


View solution in original post

10 REPLIES 10

Hi LG,



              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 select one project');


  return false;



  }




  }



}



__________________________________


Includescript



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;



  }


});


Absolute STAR!!!   Works a treat.. thank you so much 🙂


any work around for scoped applications ?



I am getting below error.


Access to getXMLWait is not available in scoped applications.


Could you send your script


Hi Harish,



I used the same script and Script Include. The problem is:



When i select the checkbox and it is populating the message. That is fine. When i selected one project from the related list then checkbox becomes unchecked. I am able to save. But when i again open the change form and it is already unchecked. When i check it again and try to save it again gives me message to add one project record in related list however one record is already added.



Please help.


Thanks in Advance.



Regards,


Punit