I have set my business rule on sys_attachment table, so that when an attachment is updated on an incident record, i can fire my update incident rule to trigger operation on Incident table. I have tried below scripts but it is not working for me

Yama2
Kilo Contributor

condition = current.table_name == "incident"

When to run : After Insert/Update

(function executeRule(current, previous /*null when async*/ ) {
    var gr = new GlideRecord("incident");
    gr.addQuery("sys_id", current.table_sys_id);
    gr.query();
	gs.log("===>record exists", gr.next());
    while(gr.next()) {
		gs.log("===>record glide", gr);
		//fi = gr.getElement('isAttachmentUpdated'); 
		gr.setValue('isAttachmentUpdated', 'Updated'); //custom field isAttachmentUpdated
        gr.update();
    }

    // Add your code here

})(current, previous);

Note: I'm able to receive the "record exists" debug as "true" but not able to get the log inside while loop. Please help me understand what is the issue fix as the custom field (isAttachmentUpdated) on incident is also not getting updated.

 

 

1 ACCEPTED SOLUTION

Hello

If this has answered your question, kindly mark the comment as a correct answer so that the question is moved to solved list.

View solution in original post

20 REPLIES 20

Yama2
Kilo Contributor

Sure, I will try this and then mark. Thanks for the suggestion. Also, can you suggest me the business rule way as i have my business rule on task so that whenever events get fired from incident, problem, change request etc i can capture in a single business rule. If i create events then i might end up with creating different events for Incident, problem and so on. So, I would really appreciate if you can provide solution from BR perspective.

No problem. you are welcome.

Yama2
Kilo Contributor

Also, can you suggest me the business rule way as i have my business rule on task so that whenever events get fired from incident, problem, change request etc i can capture in a single business rule. If i create events then i might end up with creating different events for Incident, problem and so on. So, I would really appreciate if you can provide solution from BR perspective.

fro Br, you need to perform an update on the table. But whatever you do in the BR you can do with Script action. Just have the event and script action on task table. 

Yama2
Kilo Contributor

Sure!!
Will try this way and let you know.