How to change the field on parent form based on child record.

hsingh
Mega Contributor

I have change record with three tasks underneath it   Coding,Code review and documentation. How can I make the close notes mandatory when the code review task is complete. I tried UI policies as well as client script can you help me with an example how is it possible?

1 ACCEPTED SOLUTION

Jared Healy2
Kilo Expert

For the functionality you describe, the best bet is a Display business rule for the Change Request table along with a client script to enforce the mandatory field. If you haven't used display business rule, they are quite useful. I just searched for the Wiki article but am having trouble finding it. Essentially the display business rule allows you to run code on the server side and then populate variable values into "g_scratchpad" which is then accessible on the client side when the form is displayed.



/***************************************************************


* Display business rule to be placed on the change_request table


***************************************************************/


// Scratchpad variable for your required field set to false


// until the condition is met


g_scratchpad.requireCloseNotes = 'false';




// Query the change task table for child tasks of this change


var cTask = new GlideRecord('change_task');


cTask.addQuery('change_request',current.sys_id);


cTask.query();


while(cTask.next()){


  // Loop through the tasks and validate the states or data you care about


  if(cTask.short_description == "Code Review" && cTask.state == '3')


            g_scratchpad.requireCloseNotes == 'true';


}






/*************************************************


* Client script to be placed on the change_request


* table. Must also have the business rule to work.


* Client script should be onLoad.


*************************************************/


function onLoad() {


  if(g_scratchpad.requireCloseNotes == 'true')


            g_form.setMandatory('close_notes', true);


}



Hopefully that helps.


View solution in original post

10 REPLIES 10

Hi Jared,



I completely agree with your assessment. My suggestion to use synchronous AJAX was specifically tied to making the call in an onSubmit client script. If you go with asynchronous processing in on onSubmit, the form could be submitted before the answer is returned from the script include. If the AJAX call is in an onLoad or onChange script then asych works fine.



I also like the idea of setting a scratchpad variable using a display business rule. Didn't think of that when I was writing my reply, but it gets around adding custom fields to the table while still allowing server-side querying to do the work.