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

lokeshreddy23
Giga Expert

Write a on Submit client script to query for the related list table to see if any entries are present related to the change.



If no entries exist, alert user and stop the form from saving by using "return false;"


thanks.. it's actually the script bit i'm struggling with, sorry.


If you can share the related list name and script you are working, i can be of further assistance


Thanks (sorry for the delay)



the related list is the project>parent list -     where the change is the parent (Links to pm_project.parent)