Not able to relate the change request to related list in Problem

kulkarnivivekn
Tera Contributor

Hi,

In Problem,i have created the one reference field for change request based on if change required is YES and Problem state is resolved then the attached

change should display in related list->change request tab.

I have written below business rule but its not pushing to the change request in related field.

(function executeRule(current, previous /*null when async*/) {

  // Add your code here

    var rec = new GlideRecord('change_request');

    rec.initialize();

    rec.change_request = current.rfc;

    rec.task = current.sys_id;

    rec.insert();

})(current, previous);

Please help me to do this.

1 ACCEPTED SOLUTION

It worked for me. Please check your work closely to my notes.



I added this Change Request -> Parent list on my related lists.



find_real_file.png



And here's the complete business rule used to trigger the script:



find_real_file.png


find_real_file.png


find_real_file.png


find_real_file.png


If that doesn't work, check your permissions closely to make sure the tester has create and write permission on the change_request table.


View solution in original post

19 REPLIES 19

You're still using a field called change_request on the change_request table. Did you not just say that field does not exist?



OK, let me know if I misunderstand something...


  • At some point, you want to create a change request by triggering a business rule. What that trigger is yet, I don't know.
  • When the change request is built, you want to related it to the problem request that generated it so it shows up on a related list of changes at the bottom of the form.
  • Do you also want to save the newly created change request's sys_id in the problem's RFC field?


Such a business   would look something like this. Keep in mind this is untested code.



Name: Create Change


When: Before


Advanced: true


Update: true


Insert: true


Condition: (you specify this)



Script:


(function executeRule(current, previous /*null when async*/) {



        var chg = new GlideRecord('change_request');


        chg.newRecord();


        chg.u_problem = current.sys_id; // change u_problem to your field on the change request that points to the problem or task table


        chg.short_description = 'Generated from problem ' + current.number;


        current.rfc = chg.insert();



})(current, previous);



Depending on what field you use for u_problem, you'll need to add the proper related list to the problem form. For example, if you use a field that references problem, use Problem -> Change. If you use Task, you'll need Problem -> Task. The key here is that the field and what it references needs to coordinate with the related list you choose. It's as big of a difference as having a related list of incidents or users or CIs.


Hi,



Thank you providing solution and i have tried as above but its not working.


Still i am not able to push the change request from reference field to the related list--change request tab.


Perhaps I am not understanding the requirement properly. Can you include screenshots to describe what you are trying to do? I'm sure it's not that complex.


Hi,



below reference field i have created.


ch.PNG



And same above change i want push to below related list-->change request tab


rt.PNG


Thank you. This should do the trick... keep in mind that it's untested...



Add it to an AFTER business rule like this:



Name: Update Change request parent


Table: Problem


Advanced; true



When: after


Insert: true


Update: true


Condition: current.rfc.changes()


Script:


(function executeRule(current, previous /*null when async*/) {


        var change = new GlideRecord('change_request');


        if (change.get(current.rfc)) {


                  change.parent = current.getValue('sys_id');


                  change.update();


        }



})(current, previous);