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

solutioningnow
Giga Guru

Hi Harjinder,



You have to write a client script on the change task form as, if the close notes from change record is available on the task form.



g_form.setMandatory('change_request.type',true);



Please mark answer as correct/helpful, if it was really helpful



Regards,


Solutioner


Logo.png


Enhance Knowledge NOW@ www.solutioningnow.com


http://www.solutioningnow.com/


HI



      Thanks for your quick response to my query but my situation is different. Code review task is assigned to someone else where as the change owner is someone else. I want the change owner to fill in the field once the code review task is complete next time he tries to update or even load the change record.



I hope you understand what I want to achieve here.



Regards


Harjinder


Hi Harjinder,


You need to write a BR on the Change Task table:-


Type:- On Before-Update



Condition:-current.status.changesTo(6) // Closed Complete's value is 6



var gr = new GlideRecord('change_request');


gr.addQuery('number',current.change_request);


gr.query();



while(gr.next())


{


gr.close_notes.setMandatory('true');


}



Let me know if this works, as i haven't tested this.



Thanks,


Subhajit


Hi Harjinder,



I understand your requirement, to make user interface look good you can write one display Business rule and client script.



1) Business rule: display


      Write one display business rule on the change request, and have g_scratchpad.u_review_complete = true when your code review task is completed.



Script:


g_scratchpad.review_complete = false;


var task = new GlideRecord('change_task');


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


// add one more filter to identify code review task


task.addQuery('state','6');


task.query();


if(task.next())


g_scratchpad.review_complete = true;




2) In on load client script you can check value of g_scratchpad and set close notes mandatory.


Client script




if(g_scratchpad.review_complete == true)


g_form.setMandatory('close_notes',true);




Please mark answer as correct/helpful, if it was really helpful



Regards,


Solutioner


Logo.png


Enhance Knowledge NOW@ www.solutioningnow.com


http://www.solutioningnow.com/