Business rule to change field not shown on form - skip current.update()?

kuba4
Kilo Expert

Hi There!

I need to create Incident based on Requested Item, using Business Rule, something like this:

var gr = new GlideRecord('incident');

gr.initialize();

gr.assignment_group = current.assignment_group;

gr.insert();

current.u_has_incident = true;

I have a problem with field "Has incident", which is not a form field. Without current.update() at the end, it will not be changed. On the other hand I saw few articles with advice not to use current.update() in Business rules... what should I do then to make it work?

1 ACCEPTED SOLUTION

Use an after business rule to create the incident as following



var gr = new GlideRecord('incident');


gr.initialize();


gr.assignment_group = current.assignment_group;


// add your fields that has to be ampped



gr.insert();




current.u_has_incident = true;


current.update();


current.setWorkflow(false);



The last will prevent any business rule or workflow condition to execute.



Please like or mark correct based on the impact of the response.


View solution in original post

14 REPLIES 14

Gowrisankar Sat
Tera Guru

Hi jakub,



current.update() can be used if it is onAfter Business Rule.



Write onBefore() Business Rule on sc_req_item.



var gr = new GlideRecord('incident');


gr.initialize();


gr.assignment_group = current.assignment_group;


gr.u_problem = gr.sys_id;


gr.insert();



var prob_gr = new GlideRecord('problem');


prob_gr.addQuery("u_problem",gr.sys_id);


prob_gr.query();


if(prob_gr.next())


{


prob_gr.u_has_incident = true;


prob_gr.update();


}


Use an after business rule to create the incident as following



var gr = new GlideRecord('incident');


gr.initialize();


gr.assignment_group = current.assignment_group;


// add your fields that has to be ampped



gr.insert();




current.u_has_incident = true;


current.update();


current.setWorkflow(false);



The last will prevent any business rule or workflow condition to execute.



Please like or mark correct based on the impact of the response.


istvanwellmann
Tera Contributor

Hi Jakub,


what action on your requested item should trigger an incident to be created?


kuba4
Kilo Expert

Thank you everyone for your valuable input!


Finally, I've created a business rule which on Incident insert (after) which uses GlideRecord query to flag RITM and update() glide record.



Thanks again!


HI Jak,



Please mark answer as correct and close the thread accordingly.



Thank you,
Ashutosh